0

Is there a way to set the timezone using moment.js or moment-timezone always to reflect 'America/New_York' regardless of where the user is accessing the app from?

I've tried this but the object's timezone is reflective of the browser's timezone and returns America/Los_Angeles.

moment.tz("8/26/2013 4:55 pm", "M/D/YYYY h:mm a", "America/New_York")
anm
  • 1,865
  • 3
  • 19
  • 28
  • Your syntax is totally fine here. When I run it, it produces a date with a -4 offset which is correct. When you say 'the object's timezone', what property are you looking at? – Maggie Pint Apr 08 '16 at 20:27
  • 1
    Check the debug console. Are you getting an error `"Moment Timezone has no data for America/New_York"`? If so, you don't have the tz data loaded. [See here](http://stackoverflow.com/a/33263885/634824). – Matt Johnson-Pint Apr 08 '16 at 22:58

2 Answers2

5

As stated here,

Moment.js docs

you need to include the timezone module and use it like this:

moment("8/26/2013 4:55 pm", "M/D/YYYY h:mm a").tz("America/New_York").format();
Tudor Ilisoi
  • 2,934
  • 23
  • 25
2

To change the default time zone, use moment.tz.setDefault with a valid time zone:

moment.tz.setDefault("America/New_York");

moment.js documentation

alexmac
  • 19,087
  • 7
  • 58
  • 69
  • would creating a new moment object afterwards be created under the default timezone? it seems it doesn't if my computer is set to the pacific time zone – anm Apr 12 '16 at 19:43
  • yes, new moment objects will be created with default timezone, which you set in `moment.tz.setDefault(...`. – alexmac Apr 12 '16 at 19:51