如何通过JavaScript将Unix纪元转换为[年,月,日]

我对将存储在变量中的时间戳转换doc.creation_time为格式的需求很小[year,month,day]

例子:

doc.creation_time=1537492812 应将其转换为[2018,38,Fri]

有人可以帮忙吗


慕丝7291255
浏览 109回答 2
2回答

撒科打诨

var creation_time = 1537492812;var date = new Date(creation_time * 1000);var weekday = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];// UTCconsole.log(date.getUTCFullYear(), date.getUTCMonth() + 1, weekday[date.getUTCDay()]);// Localconsole.log(date.getFullYear(), date.getMonth() + 1, weekday[date.getDay()]);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript