0

I am in Timezone A and would like to print the current time in Timezone B. For Timezone B, I have its utc_offset_b, which is a value in seconds.

How can I do this using momentjs?

Is this correct? (i'm running it in Timezone A)

moment().utc().add(utc_offset, "second").format('MMM Do, h:mm:ss a')

Ari
  • 7,251
  • 11
  • 40
  • 70
  • 1
    Possible duplicate of [Moment.js: Format date in a specific timezone](https://stackoverflow.com/questions/15347589/moment-js-format-date-in-a-specific-timezone) – Randy Casburn Oct 20 '18 at 21:30

1 Answers1

0

As long as utc_offset is the difference between the 2 offsets, this more or less does what you want.

It's important to note though that offsets are not timezones. A real timezone is usually express via a string like Europe/Amsterdam or America/Toronto.

If your model can use those timezone strings, this is much better. These timezones (which are supported by moment and many other systems) take in account things such as policy changes and daylight savings time.

Evert
  • 93,428
  • 18
  • 118
  • 189