精易论坛

标题: 分享个时间工具类 [打印本页]

作者: wqh123    时间: 2022-7-22 11:10
标题: 分享个时间工具类
const timeUtil = {
        /* 获取时间类的编号 */
        getTimeNO: function() {
                let date = new Date();
                let obj = new Object();
                obj.year = date.getFullYear();
                obj.month = this.format(date.getMonth() + 1);
                obj.day = this.format(date.getDate());
                obj.hours = this.format(date.getHours());
                obj.minutes = this.format(date.getMinutes());
                obj.seconds = this.format(date.getSeconds());
                return obj.year + '' + obj.month + '' + obj.day + '' + obj.hours + '' + obj.minutes + '' + obj.seconds;
        },
        /* 获取日期(年-月-日 时:分) */
        getTime_YMDHM: function() {
                let date = new Date();
                let obj = new Object();
                obj.year = date.getFullYear();
                obj.month = this.format(date.getMonth() + 1);
                obj.day = this.format(date.getDate());
                obj.hours = this.format(date.getHours());
                obj.minutes = this.format(date.getMinutes());
                return obj.year + '-' + obj.month + '-' + obj.day + ' ' + obj.hours + ':' + obj.minutes;
        },
        /* 获取日期(年-月-日 时:分) */
        getTime_YMDHMS: function() {
                let date = new Date();
                let obj = new Object();
                obj.year = date.getFullYear();
                obj.month = this.format(date.getMonth() + 1);
                obj.day = this.format(date.getDate());
                obj.hours = this.format(date.getHours());
                obj.minutes = this.format(date.getMinutes());
                obj.seconds = this.format(date.getSeconds());
                return obj.year + '-' + obj.month + '-' + obj.day + ' ' + obj.hours + ':' + obj.minutes+ ':' + obj.seconds;
        },
        /* 获取日期(时:分) */
        getTime_HM: function() {
                let date = new Date();
                let obj = new Object();
                obj.hours = this.format(date.getHours());
                obj.minutes = this.format(date.getMinutes());
                return obj.hours + ':' + obj.minutes;
        },
        /* 获取日期(年-月-日 时:分) */
        getTime_Y: function() {
                let date = new Date();
                let obj = new Object();
                obj.year = date.getFullYear();
                obj.month = this.format(date.getMonth() + 1);
                obj.day = this.format(date.getDate());
                obj.hours = this.format(date.getHours());
                obj.minutes = this.format(date.getMinutes());
                return obj.year;
        },
        /* 获取日期(年-月-日) */
        getTime_YMD: function() {
                let date = new Date();
                let obj = new Object();
                obj.year = date.getFullYear();
                obj.month = this.format(date.getMonth() + 1);
                obj.day = this.format(date.getDate());
                return obj.year + '-' + obj.month + '-' + obj.day
        },
        format: function(number) {
                return (number < 10 ? ('0' + number) : number);
        }
}


作者: zx83508218    时间: 2022-7-22 23:54
吼吼吼吼吼吼吼吼吼吼吼吼吼吼吼吼
作者: agz    时间: 2022-7-23 08:22
支持开源~!感谢分享
作者: jnjcsh    时间: 2022-7-23 09:20
感谢分享
作者: yzl666    时间: 2022-7-26 08:11
感谢分享
作者: lmwdz    时间: 2022-7-27 08:06
感谢分享
作者: kanke1257    时间: 2022-7-27 19:00
感谢分享
作者: lmwdz    时间: 2022-7-30 18:13
不错,学习学习
作者: asd960608    时间: 2022-7-31 07:26

不错,学习学习
作者: paneldemo    时间: 2022-8-1 09:28
getTimeNO: function() {
                let date = new Date();
                let obj = new Object();
                obj.year = date.getFullYear();
                obj.month = this.format(date.getMonth() + 1);
                obj.day = this.format(date.getDate());
                obj.hours = this.format(date.getHours());
                obj.minutes = this.format(date.getMinutes());
作者: plus    时间: 2022-8-4 20:12
支持开源~感谢分享




欢迎光临 精易论坛 (https://125.confly.eu.org/) Powered by Discuz! X3.4