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

留个记录,回头直接拿着用

// Mon Aug 17 2020 16:29:29 GMT+0800 (中国标准时间) 转 年月日时分秒
function timeD(time) {
    let d = new Date(time),
        data = {
            'year': d.getFullYear(),
            'month': this.timeP(d.getMonth() + 1),
            'day': this.timeP(d.getDate()),
            'hour': this.timeP(d.getHours()),
            'min': this.timeP(d.getMinutes()),
            'sec': this.timeP(d.getSeconds()),
        }
    return data;
},

// 补0
function timeP(s) {
    return s < 10 ? '0' + s : s
},

// 年月日时分秒 转 Mon Aug 17 2020 16:29:29 GMT+0800 (中国标准时间)
function timeG(time) {
    let t = Date.parse(time);
    if (!isNaN(t)) {
        return new Date(t)
    }
}
 


版权声明:本文为ForestRoar原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。