Moment.js amDateFormat always returning date from 1970

前端 未结 2 842
故里飘歌
故里飘歌 2021-01-11 18:20

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

相关标签:
2条回答
  • 2021-01-11 18:20

    Try to write own filter, like this:

     newapp.filter("fromTimestamp", function(){
       return function(timestamp, format){
         return moment.unix(timestamp).format(format)
       }
     })
    

    And use them

    <p class="date">{{date | fromTimestamp:'ffffdd, MMMM Do YYYY'}}</p>
    

    Plunker demo

    0 讨论(0)
  • 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}}
    
    0 讨论(0)
提交回复
热议问题