the*_*del 3 date datetime-format node.js node-modules
我得到一个像这样以毫秒为单位的日期
1525520235000
我想将其转换为当地时间
2018 年 5 月 5 日星期六 17:22:15
如何在 NodeJS 中完成此操作?谢谢。
可能这有帮助:
date = new Date(1525520235000);
date.toString();
Run Code Online (Sandbox Code Playgroud)
结果是这样的:
“2018 年 5 月 5 日星期六 18:37:15 GMT+0700(东南亚标准时间)”
所有函数的列表get在这里:https ://www.w3schools.com/js/js_date_methods.asp
let x = 1525520235000;
const mydate = new Date(x);
const month = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
][mydate.getMonth()];
var day = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][mydate.getDay()];
console.log('Day: ', day);
console.log('Month: ', month);
console.log('Year: ', mydate.getFullYear());
console.log("Hours: ", mydate.getHours());
console.log("Mitutes: ", mydate.getMinutes());
console.log(mydate.toString("MMMM yyyy"));Run Code Online (Sandbox Code Playgroud)