On my Chromium 121 the following Intl.DateTimeFormat
works fine:
new Intl.DateTimeFormat('en', {
dateStyle: 'long',
timeStyle: 'long',
timeZone: '+0500',
}).format(new Date());
> 'February 18, 2024 at 3:42:40 AM GMT+5'
The same on a Chrome Headless 114.0.5673.0 fails with Invalid time zone specified: +0500
.
Could help me point out when/in which version this timezone format got supported ?
2
Answers
The ability to specify a time zone using an offset in the format +hhmm or -hhmm in Intl.DateTimeFormat isn’t directly tied to a specific version of Chrome, as this is part of the ECMAScript Internationalization API implemented in browsers. However, if a specific version of Chrome is failing, it might be due to how that version handles time zones or a bug. The information on time zone handling might not be version-specific or might not be documented in the Chrome version history in a straightforward manner. It is advisable to test across different versions or consult the Chrome release notes for specific updates related to Intl.DateTimeFormat.
From everything I can find, it should have been supported as of version 24.
I also tested your code on the latest Firefox and it worked fine.
Granted, the documentation states it MUST support GMT and MAY support IANA time zones, but does not say anything about offsets:
So technically, implementations could support no time zones at all, but the vast majority of apps should support the IANA time zones.
You can try using the IANA timezone offset name:
If that does not work, it is more likely some kind of issue in your setup. Also note that I used the opposite offset (-5 instead of +5). This is just how the IANA timezone Etc offset names are designed: they are the opposite of what the actual offset is (Etc/GMT-5 is actually +0500 and Etc/GMT+5 is actually -0500).