我有一个时间戳 1378028575
给我 Sun, 01 Sep 2013 09:42:55 GMT
here .但是,当我尝试使用 Angular date
对其进行格式化时,它会将其返回为 Jan 17, 1970 2:47:08 AM
,使用以下格式:{{' 1378028575' |日期:'中等'}}
。该站点的结果是正确的,但在 Angular 中是错误的。为什么会发生,或者我做错了什么?
最佳答案
这是因为您使用的是秒而不是毫秒。
new Date(1378028575)
Fri Jan 16 1970 23:47:08 GMT+0100 (CET)
new Date(1378028575000)
Sun Sep 01 2013 11:42:55 GMT+0200 (CEST)
来自 Angular 文档:
Date to format either as Date object, milliseconds (string or number) or various ISO 8601 datetime string formats (e.g. yyyy-MM-ddTHH:mm:ss.SSSZ and its shorter versions like yyyy-MM-ddTHH:mmZ, yyyy-MM-dd or yyyyMMddTHHmmssZ). If no timezone is specified in the string input, the time is considered to be in the local timezone.
关于javascript - AngularJS 错误的 unix 时间解析结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18696299/