MomentJS时间戳解析显示错误的日期 [英] MomentJS timestamp parsing shows wrong date
问题描述
我在Angular项目中使用了JS瞬间,并且尝试解析从服务器获取的时间戳.
I am using moment JS in my Angular project and I tried to parse a timestamp I got from server.
问题在于力矩输出:January 18, 1970 4:03 PM
作为时间戳:1526636521
.这不是我从在线时代转换器得到的. (Friday, May 18, 2018 9:42:01 AM
)
the problem is that moment outputs : January 18, 1970 4:03 PM
for the timestamp : 1526636521
. which is not what I get form the online epoch converter. ( Friday, May 18, 2018 9:42:01 AM
)
这是我的即时通话:moment.utc(data.TimeStamp).format('LLL')
;
this is my moment call : moment.utc(data.TimeStamp).format('LLL')
;
推荐答案
由于您使用的电话号码是number of seconds from 1970 Jan 1st
,
As the number you are using is number of seconds from 1970 Jan 1st
,
moment.utc
接受number of milliseconds
,
所以要么使用,
moment.unix(1526636521).toString()
//moment.unix花费的秒数
moment.utc(1526636521000).toString()
//向数字添加三个零.
moment.unix(1526636521).toString()
// moment.unix takes in number of seconds
moment.utc(1526636521000).toString()
// Add three zeros to number.
这篇关于MomentJS时间戳解析显示错误的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!