Invalid time zone specified: US/Alaska, US/Arizona, US/Mountain, US/Central etc error in Chrome but working in Mozilla

kiran goud picture kiran goud · Aug 29, 2019 · Viewed 9.3k times · Source

I am trying to convert timestamp in to various time zone's local time and found certain TimeZone are not supporting in Chrome (v76.0.38) but working fine in Mozilla (v68.0.2).

  let d = new Date(1567083463);
  let n = d.toLocaleString('en-GB', { timeZone: "US/Arizona" });
  

Uncaught RangeError: Invalid time zone specified: US/Arizona

at Date.toLocaleString ()

Several other timezones are also throwing the same error

US/Alaska US/Mountain US/Central US/East-Indiana

These timezones are officially supported as mentioned in their website Chrome Supported Time Zone Values

Answer

user47589 picture user47589 · Aug 29, 2019

That page describes timezones supported by another google product, not Chrome.

Referring to MDN's documentation on toLocaleString:

timeZone
The time zone to use. The only value implementations must recognize is "UTC"; the default is the runtime's default time zone. Implementations may also recognize the time zone names of the IANA time zone database, such as "Asia/Shanghai", "Asia/Kolkata", "America/New_York".

Valid time zones can be found at that IANA link, or you can use Wikipedia: List of tz database time zones. You'll notice that all of the "US/*" timezones are deprecated. Use only Canonical entries from the Wikipedia page, such as:

  • America/New_York
  • America/Denver
  • America/Chicago

etc.