Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moment converting wrong time. #378

Closed
mahadazad opened this issue Sep 2, 2016 · 4 comments
Closed

Moment converting wrong time. #378

mahadazad opened this issue Sep 2, 2016 · 4 comments

Comments

@mahadazad
Copy link

mahadazad commented Sep 2, 2016

Hello I am trying to convert UTC time to "Canada/Eastern" and its converting time one hour behind

> moment('2016-09-01T18:04:01Z').tz('Canada/Eastern').format();
> "2016-09-01T14:04:01-04:00"

but the actual time should bd 15:04:01

http://www.timeanddate.com/worldclock/converted.html?iso=20160901T1805&p1=0&p2=286

@mattjohnsonpint
Copy link
Contributor

Canada/Eastern is an alias for America/Toronto. You picked Halifax on the t&d link, which is in Atlantic time, not Eastern time.

Refer to:
https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

And in general, you should prefer canonical locality-based zone identifiers rather than legacy links.

@mattjohnsonpint
Copy link
Contributor

Also, your code would be slightly cleaner as:

moment.tz('2016-09-01T18:04:01Z', 'Canada/Eastern').format();

Not that the other way is wrong, just it has an interim state where the moment is in local time. This way the moment is constructed in the original time zone.

@mahadazad
Copy link
Author

mahadazad commented Sep 4, 2016

@mj1856 Ok thanks for the info. By the way I was using moment.tz.names() method to pull the time zones, but seems it also returns the deprecated ones. Is it some other way which can help me pull only valid time zones not the deprecated ones?

@mattjohnsonpint
Copy link
Contributor

@mahadazad - there's an item open for that in #227. We currently aren't working on it actively, but will always take a PR if someone is inclined to attempt it. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants