Moment.js amDateFormat always returns a date since 1970

http://plnkr.co/edit/5zxXEEz30t51yGhgYWVF?p=preview

I am using Moment.js and Angular-moment in my application.

For some reason, it converts all of my era timestamps to the same date since 1970.

enter image description here

<td class="timespan">{{tag.added_epoch | amDateFormat:'dddd, MMMM Do YYYY'}}</td>

This value tag.added_epoch added_epoch: 1432252800

However, when I convert it online, I get the correct date:

enter image description here

Any idea why my filter turns 1432252800on Saturday, January 17, 1970 ?

+4
source share
2 answers

I just quickly summarize the problem and the solution.

Moment.js unix moment(1432252800) moment.unix(1432252800).

(1 1970 12:00 UTC), moment() , 17 , moment.unix() - .

angular -moment amFromUnix, .

<time am-time-ago="myDate|amFromUnix">
{{myDate|amFromUnix|amCalendar}}
+7

, :

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

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

- Plunker

+2

Source: https://habr.com/ru/post/1626584/


All Articles