Moment.js amDateFormat always returning date from 1970(Moment.js amDateFormat 总是返回 1970 年的日期)
问题描述
<td class="timespan">{{tag. added_epoch |amDateFormat:'dddd, MMMM Do YYYY'}}</td>
这就是 tag.added_epoch
值是 added_epoch: 1432252800
但是当我在线转换时,我得到了正确的日期:
知道为什么我的过滤器会将 1432252800
变成 Saturday, January 17th 1970?
我只是快速总结问题和解决方案.
Moment.js 提供了两种不同的方法来根据 unix 时间戳创建日期moment(1432252800)
和 moment.unix(1432252800)
.
两者同时开始(1970 年 1 月 1 日凌晨 12 点 UTC),但 moment()
使用以毫秒为单位的数字,大约是 17 天和 moment.unix()
使用秒数.
angular-moment 支持 amFromUnix
过滤器,参见 来源
你可以通过以下方式使用它
<time am-time-ago="myDate|amFromUnix">{{myDate|amFromUnix|amCalendar}}
http://plnkr.co/edit/5zxXEEz30t51yGhgYWVF?p=preview
I'm using Moment.js and Angular-moment in my app.
For some reason it's converting all my epoch timestamps to the same date from 1970.
<td class="timespan">{{tag.added_epoch | amDateFormat:'dddd, MMMM Do YYYY'}}</td>
This is what the tag.added_epoch
value is added_epoch: 1432252800
However when I convert it online, I get the correct date:
Any idea why my filter is turning 1432252800
into Saturday, January 17th 1970?
I'm just quickly summarizing the problem and solution.
Moment.js offers two different ways to create a date from a unix timestamp
moment(1432252800)
and moment.unix(1432252800)
.
Both start at the same time (Jan 1 1970 12AM UTC) but moment()
uses the number as milliseconds, which are around 17 days and moment.unix()
uses seconds.
angular-moment supports the amFromUnix
filter, see source
You can use it the following way
<time am-time-ago="myDate|amFromUnix">
{{myDate|amFromUnix|amCalendar}}
这篇关于Moment.js amDateFormat 总是返回 1970 年的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Moment.js amDateFormat 总是返回 1970 年的日期


- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 失败的 Canvas 360 jquery 插件 2022-01-01