问题
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