I'm trying to use Moment.js to convert a Unix epoch time to a date and time. I'd also like to know how to have it formatted like below.
我正在尝试使用Moment.js将Unix纪元时间转换为日期和时间。我也想知道如何将其格式化如下。
Tuesday, November 22, 2016 6:00 PM
2016年11月22日星期二下午6点
3 个解决方案
#1
19
moment.unix(yourUnixEpochTime).format('dddd, MMMM Do, YYYY h:mm:ss A')
#2
8
From the Docs: Unix Timestamp
来自Docs:Unix时间戳
var day = moment.unix(1318781876); //seconds
var day = moment(1318781876406); //milliseconds
// and then:
console.log(day.format('dddd MMMM Do YYYY, h:mm:ss a'));
// "Sunday October 16th 2011, 9:17:56 am"
#1
19
moment.unix(yourUnixEpochTime).format('dddd, MMMM Do, YYYY h:mm:ss A')
#2
8
From the Docs: Unix Timestamp
来自Docs:Unix时间戳
var day = moment.unix(1318781876); //seconds
var day = moment(1318781876406); //milliseconds
// and then:
console.log(day.format('dddd MMMM Do YYYY, h:mm:ss a'));
// "Sunday October 16th 2011, 9:17:56 am"