4

I have a date string from an API containing a timezone using abbreviations:

"01/16/2018 12:15pm PST"

Moment.js seems to ignore the timezone though, even if I use the z timezone input parsing string. That only seems to handle timezones strings that are time offsets like -10:00

For example, I would expect these two commands to return different values, because they have different timezone strings ('PST' and 'UTC')

moment('01/01/1990 02:03pm PST', 'MM/DD/YYYY hh:mma z').format('h:mm A')
moment('01/01/1990 02:03pm UTC', 'MM/DD/YYYY hh:mma z').format('h:mm A')

But they both return "2:03 PM"

I'm also using moment-timezone, as in import moment from 'moment-timezone';, but this does not seem to add the parsing functionality for timezone strings.

Andy Ray
  • 30,372
  • 14
  • 101
  • 138
  • 3
    There is no [*parse token*](https://momentjs.com/docs/#/parsing/string-format/) for civil timezone designators like "PST" because there is no standard to define them. Some, like "EST", can represent 3 different offsets. If you want to use an offset like PST, convert it to an offset yourself and reformat the string into RFC 2822 format, e.g. Mon Jan 01 1990 14:03 GMT-0800 (PST). But likely much easier to generate a Date as UTC and offset it by -8:00 manually. – RobG Feb 07 '18 at 08:18

0 Answers0