JS时间格式转化(20231101100501)转化为xxxx-xx-xx xx:xx:xx格式

直接上代码

let timestamp = 20231101100501;
let timestampStr = timestamp.toString();
let year = timestampStr.slice(0, 4);
let month = timestampStr.slice(4, 6);
let day = timestampStr.slice(6, 8);
let hours = timestampStr.slice(8, 10);
let minutes = timestampStr.slice(10, 12);
let seconds = timestampStr.slice(12, 14);
let formattedDateTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
console.log(formattedDateTime);

猜你喜欢

转载自blog.csdn.net/m0_65209474/article/details/134204061
xx