我得到的时间戳记为“2020-03-02T05:50:31.000Z”

如何将其转换为带有日期和时区的普通可读格式

最佳答案

const parsedDate = new Date("2020-03-02T05:50:31.000Z");
console.log(parsedDate.toGMTString())
//"Mon, 02 Mar 2020 05:50:31 GMT"
console.log(parsedDate.toLocaleString())
//"3/2/2020, 11:20:31 AM"
console.log(parsedDate.toDateString(), parsedDate.toTimeString())
//Mon Mar 02 2020 11:20:31 GMT+0530 (India Standard Time)

09-08 06:38