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

Construct a moment from date, time and timezone, then format it back with timezone #26

Closed
nareshbhatia opened this issue Aug 16, 2013 · 3 comments

Comments

@nareshbhatia
Copy link

Two part question:

  • Is it possible to construct a moment from a date, time and timezone? For example how do I construct August 15, 2013, 1:00 PM in timezone = "America/Chicago"? I think [PR Alternative construct moment local to timezone #25] addresses this but I can't be sure.

  • How do I fomat such a moment back with a timezone abbreviation, for example "15 Aug 2013 01:00 PM CDT". I tried the following, but it prints the timezone as an offset.

    moment("08/15/2013 1:00 PM -0500", "MM/DD/YYYY hh:mm A Z")
    .tz('America/Chicago')
    .format('DD MMM YYYY hh:mm A Z');

produces

15 Aug 2013 01:00 PM -05:00

Timezone is printed as offset, not as CDT

@mattjohnsonpint
Copy link
Contributor

#25 does handle the first part, as discussed in #11. Regarding abbreviations, we have an open item in #4.

However you should know that time zone abbreviations are not standardized worldwide, and there are many ambiguities. So if they are supported, it would be for display only. They would work with .format(), but would be ignored when parsing.

Currently you can use .zoneName() or .zoneAbbr() to pull out the abbreviation, but there is no specific format token yet.

@timrwood
Copy link
Member

z and zz have been added back into moment for formatting the timezone name and abbreviations. (although they do require moment-timezone or another library to override moment#zoneName and moment#zoneAbbr)

@mattjohnsonpint
Copy link
Contributor

Nice. Thanks!

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

3 participants