-1

Given a moment time, how do you change the timezone without changing the actual time?

For example if you have 2020-06-19 16:30:00+00 but you want this in America/New_York timezone.

The output would be 2020-06-19 16:30:00-04:00 (currently Daylight Savings time).

b.lyte
  • 6,518
  • 4
  • 40
  • 51

1 Answers1

0

You can do this by using the .tz(.., true) function.

From the Moment Timezone docs (https://momentjs.com/timezone/docs/#/using-timezones/converting-to-zone/):

On passing a second parameter as true, only the timezone (and offset) is updated, keeping the local time same. Consequently, it will now point to a different point in time if the offset has changed.

m.format();                           // 2013-11-18T11:55:00-05:00
m.tz('Europe/Berlin', true).format()  // 2013-11-18T11:55:00+01:00
b.lyte
  • 6,518
  • 4
  • 40
  • 51