我有一个小需求,我想将存储在变量 doc.creation_time
中的时间戳转换为格式 [year,month,day]
例子:
doc.creation_time
= 1537492812
这应该转换为 [2018,38,Fri]
谁能帮忙
最佳答案
var creation_time = 1537492812;
var date = new Date(creation_time * 1000);
var weekday = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
// UTC
console.log(date.getUTCFullYear(), date.getUTCMonth() + 1, weekday[date.getUTCDay()]);
// Local
console.log(date.getFullYear(), date.getMonth() + 1, weekday[date.getDay()]);
关于javascript - 如何通过javascript将unix纪元转换为[年,月,日],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55953967/