0

Get following date from JSON response: 1470995100000 But angular-moment will convert this long to the current date + timezone offset. How can i avoid this?

{{ item.startDate | amDateFormat:'HH:mm' }}

Should be = 07:55 (correct value from database - always based on local timezone). But for example 09:55 will be displayed (if the timezone on the local machine was changed)

Kind regards

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
Benni
  • 91
  • 1
  • 1
  • 7

2 Answers2

2

Have you tried moment.utc(...) ?

fibuszene
  • 41
  • 6
  • myApp.run(function(amMoment) { amMoment.changeTimezone("Europe/Berlin"); )}; solved my problem. – Benni Nov 05 '15 at 15:11
  • @Benni - Berlin is UTC+1 or UTC+2 depending on summer time. For the value you provided, Berlin would be `2016-08-12T11:45:00+02:00`, which is not what you asked for in the question. – Matt Johnson-Pint Nov 05 '15 at 16:44
1

The value 1470995100000 is a representation that is the number of milliseconds since the Unix Epoch (1970-01-01T00:00:00Z), corresponding to 2016-08-12T09:45:00Z.

Assuming 9:55 was a typo and you meant 9:45, then you simple are asking for your code to display the UTC time.

While fizbuszene's answer is correct from a moment.js perspective, your question was about the angular-moment library's declarative form. You simply need to use their amUtc filter, as shown in the documentation.

{{ item.startDate | amUtc | amDateFormat:'HH:mm' }}
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575