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

Question - Localized Date Format by Timezone #453

Closed
lwelti opened this issue Jun 15, 2015 · 1 comment
Closed

Question - Localized Date Format by Timezone #453

lwelti opened this issue Jun 15, 2015 · 1 comment

Comments

@lwelti
Copy link

lwelti commented Jun 15, 2015

Maybe I am missing it, but I don't see a way to get the Localized DateTime Format based on the Time Zone.
Having:
var testDate = new Date(Date.UTC( 2014, 2, 21, 0, 0, 0 ));
formatDate( testDate, { datetime: "medium" });

and for 2 different Time Zones get a different Output:

A) for Time Zone: America/Los_Angeles get:
Mar 20, 2014, 5:00:00 PM

B) for America/Mexico_City get:
Mar 20, 2014, 7:00:00 PM

I didn't see a way to pass the TZ, but maybe I am missing it.
thanks

@rxaviers

@rxaviers rxaviers added the docs label Jun 16, 2015
@rxaviers
Copy link
Member

rxaviers commented Jun 18, 2015

Hi Lucas,

Globalize doesn't try to overcome any native JavaScript timezone limitations (more info at #202). Therefore, our current timezone support provides simple coverage (you can't set an arbitrary timezone and we skip some formatting patterns). We keep the enhanced date timezone module open on #340, which will rely on a third-party library that supports Olson timezones and advanced manipulations.

Having said that, there are fields for formatting the local timezone, which are z..zzz, Z..ZZZZZ, O,OOOO, x..xxxxx, and X..XXXXX (more info at http://www.unicode.org/reports/tr35/tr35-dates.html), or by using time (or datetime) long or full. For example:

Globalize("en").formatDate(new Date(), {time:"long"});
// > '10:04:55 AM GMT-3'

Globalize("en").formatDate(new Date(), {datetime:"long"});
// > 'June 18, 2015 at 10:05:11 AM GMT-3'

Globalize("en").formatDate(new Date(), {raw: "OOOO"});
// > 'GMT-03:00'

Globalize("en").formatDate(new Date(), {raw: "z"});
// > 'GMT-3'

Globalize("en").formatDate(new Date(), {raw: "Z"});
// > '-0300'

Please, let me know on any questions.

I'm leaving this bug opened until we improve the timezone explanations on /doc/api/date/date-formatter.md. Would you be interested in helping out? Thanks.

  • Improve timezone explanation on /doc/api/date/date-formatter.md.

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

No branches or pull requests

2 participants