JS时间格式转换 Mon Aug 25 2020 16:29:29 GMT+0800 (中国标准时间)

时间格式转换 Mon Aug 17 2020 16:29:29 GMT+0800 (中国标准时间)
转换结果:2020-08-25 16:29:29

      const modifyTime =  this.dateControlFunc(new Date)

       dateControlFunc(date) {
            const year = date.getFullYear()
            const month = date.getMonth() + 1
            const day = date.getDate()
            const hour = date.getHours()
            const minutes = date.getMinutes()
            const second = date.getSeconds()
            const updateDate = year + '-' + this.fix(month, 2) + '-' + this.fix(day, 2) + ' ' + this.fix(hour, 2) + ':' + this.fix(minutes, 2) + ':' + this.fix(second, 2)
            return updateDate
        },
        fix(num, length) { // 两位补0
            return ('' + num).length < length ? ((new Array(length + 1)).join('0') + num).slice(-length) : '' + num
        }

你可能感兴趣的:(JS时间格式转换 Mon Aug 25 2020 16:29:29 GMT+0800 (中国标准时间))