skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. 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:

    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".

    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:

    new Intl.DateTimeFormat('en', {
        dateStyle: 'long',
        timeStyle: 'long',
        timeZone: 'Etc/GMT-5',
    }).format(new Date());
    
    "February 18, 2024 at 3:42:40 AM GMT+5"
    

    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).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search