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

房东的猫 提交于 2020-06-09 07:09:27

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/57710861/invalid-time-zone-specified-us-alaska-us-arizona-us-mountain-us-central-etc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!