0

moment("2013-12-31T19:51:57.000-0800").format("HH:mm") yields a 24hr hour format in GMT but I would like it in local time "11:51".

Is this possible with moment's format method?

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
nesbert
  • 125
  • 5
  • Is this related? http://stackoverflow.com/questions/15347589/moment-js-format-date-in-a-specific-timezone – Jeff Dec 31 '13 at 21:46

1 Answers1

0

That is incorrect. The code you gave will not show the the value in GMT. It will first adjust using the offset you gave it (-08:00), and then it will convert it to the correct offset as your own local time zone. So if you're time zone offset happens to be -08:00 for that particular time, you will see no conversion at all.

Also, you seem to be misunderstanding how the offset is applied. When you have an offset on an ISO8601 formatted string (like the one you supplied here), that means the time is already in the offset that is supplied. 19:51 is the local time that is in effect at the -8:00 offset.

To convert to UTC / GMT - you need to first invert the sign, then apply it. So the UTC time here is 3:51:57 AM on 2014-01-01.

Your requested output of 11:51 is not valid for this timestamp, no matter how you look at it.

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
  • You are correct! My rush to celebrate the new year I totally missed that our API was returning the wrong offset. Thanks! – nesbert Jan 02 '14 at 17:42