我对将存储在变量中的时间戳转换doc.creation_time为格式的需求很小[year,month,day]例子:doc.creation_time=1537492812 应将其转换为[2018,38,Fri]有人可以帮忙吗
2 回答
撒科打诨
TA贡献1934条经验 获得超2个赞
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()]);
添加回答
举报
0/150
提交
取消