0

How can i change the timezone without changing the date/time in moment / moment-timezone?

e.g 15/01/2016 09:00:00 +02:00
to e.g 15/01/2016 09:00:00 +00:00

I have tried the solution as posted in the following links post, however this relies on a utcOffset() function which moment complains as being deprecated.

Reading the thread there is an example which states something such as the following might work (but it does not) although i see where the author is going.

moment.tz(moment(date).format("DD/MM/YYYY hh:mm:ss"), "America/Los_Angeles")

This complains of Invalid Date.

Community
  • 1
  • 1
Piotr Stulinski
  • 9,241
  • 8
  • 31
  • 46
  • `utcOffset` is not deprecated. What's deprecated is passing a string to the moment constructor (your `date` variable`) without specifying its format. – Matt Johnson-Pint Jan 15 '16 at 19:22
  • Also, you should never format a date to a string just to parse it back to an object again. As I answered in the other question, you just mutate the exiting moment object by calling `.tz` on it, instead of `.utcOffset`. – Matt Johnson-Pint Jan 15 '16 at 19:25
  • Answered in the comments of the other question. Voting to close as duplicate, since this question doesn't add anything significant. – Matt Johnson-Pint Jan 15 '16 at 19:30
  • I am unable to get that to do what it needs to. Calling .tz actually changes the time element. I simply want to change the 'zone' element. – Piotr Stulinski Jan 15 '16 at 19:33
  • You still have to shift it back, which is the very next line of code. As I said in that answer, doing this shifting gives you a completely different moment in time, and is not recommended. – Matt Johnson-Pint Jan 15 '16 at 19:53
  • I've expanded my answer in the dup post. – Matt Johnson-Pint Jan 15 '16 at 20:00

0 Answers0