javascript - AngularJS 错误的 unix 时间解析结果

标签 javascript unix angularjs timestamp

我有一个时间戳 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/

相关文章:

javascript - Sonar 中的 coverage_exclusions 与 exclusions 之间有什么区别?

javascript - 如何从 React 组件中渲染整个树?

javascript - 第一次加载时出现 Angularjs $on $routeChangeSuccess 错误

javascript - 独立的 Angular 脚本和数据位于单个文件中

javascript - 我如何将范围限制为单击的元素?

javascript - 如何在数组中获取数组中的值

php - 关注由 ajax 创建的文本框

linux - 为什么在 `tar cf` 之前通过 `gzip` 运行我的文件会更改其内容?

linux - 使用脚本 bash/expect 保持 ssh session 事件

bash 和 telnet 来测试电子邮件