【js】格式化时间 2022-08-06T11:11:07+08:00 =》 2022-08-06 11:11:07

transformTimestamp(timestamp) {
        let a = new Date(timestamp).getTime();
        const date = new Date(a);
        const Y = date.getFullYear() + '-';
        const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
        const D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + '  ';
        const h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
        const m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
        const s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()); //
        const dateString = Y + M + D + h + m + s;
        // console.log('dateString', dateString); // > dateString 2021-07-06 14:23
        return dateString;
      }

 

 
posted @ 2022-08-25 16:25  狂扇赵四那半拉好嘴  阅读(1359)  评论(0编辑  收藏  举报