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

Intl.DateTimeFormat().resolvedOptions().timeZone returns wrong value of timezone #754

Closed
vsharmaMitel opened this issue May 30, 2019 · 11 comments

Comments

@vsharmaMitel
Copy link

vsharmaMitel commented May 30, 2019

I want to fetch timezone in IANA form for a user using javascript function Intl.DateTimeFormat().resolvedOptions().timeZone. But this function gives incorrect IANA time zone value.

I have used moment.js library's function moment.tz.guess(true). But this also gives same incorrect value. On further analysis, I came to know that this also uses same native js function Intl.DateTimeFormat().resolvedOptions().timeZone internally

var timeZone = moment.tz.guess(); // "America/Los_Angeles"

or

var timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone; // "America/Los_Angeles"

Though the user has set system time to (UTC - 07:00) Mountain Time (US & Canada), but still this function gives value as "America/Los_Angeles" which is Pacific standard/daylight timezone. Whereas expected value should be "America/Denver".
Another thing is that this issue started occurring after the daylight savings adjustment came into picture i.e. around mid of March. Beforehand it worked fine. The user is located in Utah, USA.

Can anyone suggest probable root causes of this issue? Also please suggest any workaround, would be very helpful..

@ellenaua
Copy link
Contributor

ellenaua commented Sep 7, 2019

@vsharmaMitel this is the best way to detect user timezone -
Intl.DateTimeFormat().resolvedOptions().timeZone

Which value did it return to you?
This function may not work in some browsers, but if it works - it should return a correct value.

@vsharmaMitel
Copy link
Author

@ellenaua I guess this problem is related to chromium version. In older version of chromium based on which I have created my desktop application, it shows value of Intl.DateTimeFormat().resolvedOptions().timeZone as "America/Los_Angeles" whereas in latest version of chromium (which is available in my chrome browser), the value is coming correctly as "America/Denver". So it seems there was some chromium bug which got fixed later on.

@ellenaua
Copy link
Contributor

I see, it's resolved then

@steele-cjf
Copy link

so,what is the solution?

@andyyou
Copy link

andyyou commented Dec 20, 2021

Is there a solution? I get the totally wrong timezone on windows 11 with all browsers. Chrome, Firefox, Brave all got Etc/GMT-8 but Asia/Taipei is the right one.

@vsharmaMitel
Copy link
Author

vsharmaMitel commented Dec 20, 2021

Is there a solution? I get the totally wrong timezone on windows 11 with all browsers. Chrome, Firefox, Brave all got Etc/GMT-8 but Asia/Taipei is the right one.

Can you tell me your windows system timezone?

@andyyou
Copy link

andyyou commented Dec 20, 2021

@vsharmaMitel UTC+8. Thanks for reply I reset and set timezone again. Finially solved it.

@vsharmaMitel
Copy link
Author

vsharmaMitel commented Dec 20, 2021

@vsharmaMitel UTC+8. Thanks for reply I reset and set timezone again. Finially solved it.

Not a problem. I just checked by setting system time to UTC+8 Taipei, and i am able to get the timezone as 'Asia/Taipei' in browser.

@rodrigochapeta
Copy link

I'm getting America/Buenos_Aires when the INAI it´s America/Argentina/Buenos_Aires

@tafelnl
Copy link

tafelnl commented Sep 29, 2022

@rodrigochapeta Seems to be a bug in Chromium. Firefox actually returns the correct value America/Argentina/Buenos_Aires. But Chrome returns America/Buenos_Aires

Tested on:
System: Linux 5.15.0-48-generic x86_64 with Ubuntu 20.04.5 LTS

Firefox 104.0 (64-bit)
Chrome Version 106.0.5249.61 (Official Build) (64-bit)

@Chakit22
Copy link

May I know how exactly to test if this works correctly Intl.DateTimeFormat().resolvedOptions().timeZone ? How exactly does this fetch the location of the user?

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

7 participants