Search code examples
javascriptangularjstimezonemomentjsangular-moment

Display datetime from json without formatting to locale timezone in javascript with moment.js


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


Solution

  • 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' }}