I have a timestamp 1378028575
that gives me Sun, 01 Sep 2013 09:42:55 GMT
here. But when I try to format it with Angular date
, it returns it as Jan 17, 1970 2:47:08 AM
, using this format: {{'1378028575' | date:'medium'}}
. The result from the site is correct but in Angular is wrong. Why does it happen, or what am I doing wrong?
Its cause you use seconds not milliseconds.
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)
from the angular docs:
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.
The other answer isnt quite complete. Since your timestamp is in seconds, not miliseconds, in Angular.js you can do this:
{{1378028575 * 1000 | date:'medium'}}
Knowing seconds * 1000 = miliseconds is one thing. Knowing you can put math in the date expression is another :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With