jokab
jokab

Reputation: 688

Why conversion from utc and back using momentjs is missing a day

I want to convert 2018-05-16 01:30 to utc and back

moment("2018-05-16 01:30").tz("America/Anchorage").utc() == "2018-05-15 17:30"
moment("2018-05-15 17:30").tz("America/Anchorage") == "2018-05-15 01:30:00"

It's missing a day! 2018-05-15 01:30 instead of 2018-05-16 01:30

Any help is appreciated.

Upvotes: 1

Views: 80

Answers (1)

jokab
jokab

Reputation: 688

I was using momentjs incorrectly. It should be used as so:

moment.tz("2018-05-16 01:30", "America/Anchorage").utc().format() == "2018-05-16 09:30"
moment.utc("2018-05-16 09:30", "YYYY-MM-DD H:mm").tz("America/Anchorage") == "2018-05-16 01:30"

Upvotes: 2

Related Questions