码迷,mamicode.com
首页 > Web开发 > 详细

JS - 2020-01-01T00:00:00.000000Z 日期格式转换

时间:2020-06-28 18:08:50      阅读:927      评论:0      收藏:0      [点我收藏+]

标签:code   str   span   return   ring   转换   数据格式   数据   ace   

 

日期格式转换

2020-06-27T14:20:27.000000Z 时间格式转换成 2020-06-27 14:20:27
function rTime(date) {
    var json_date = new Date(date).toJSON();
    return new Date(new Date(json_date) + 8 * 3600 * 1000).toISOString().replace(/T/g, ‘ ‘).replace(/\.[\d]{3}Z/, ‘‘) 
}
let date = rTime(‘2020-06-27T14:20:27.000000Z‘);
console.log(date) // 2020-06-27 14:20:27

toJSON() 方法可以将 Date 对象转换为字符串,并格式化为 JSON 数据格式。

 

JS - 2020-01-01T00:00:00.000000Z 日期格式转换

标签:code   str   span   return   ring   转换   数据格式   数据   ace   

原文地址:https://www.cnblogs.com/sanyekui/p/13204062.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!