js将 “2021-07-06T06:23:57.000+00:00” 转换为年月日时分秒


 

 

//将“2021-07-06T06:23:57.000+00:00” ,转换为2021-07-06 14:23
let orderTime = "2021-07-06T06:23:57.000+00:00";
console.log( this.transformTimestamp(orderTime) ); //输出2021-07-06 14:23





//
时间转换 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(); // 秒 const dateString = Y + M + D + h + m; // console.log('dateString', dateString); // > dateString 2021-07-06 14:23 return dateString; },

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM