How to Translate Between Windows and Iana Time Zones

How to translate between Windows and IANA time zones?

Current Status:

Starting with .NET 6, both forms of time zones are supported on any platform that has both time zone data and ICU installed, which is most installations of Windows, Linux, and MacOS. See Tobias's answer.

Original Answer:

The primary source of the data for conversion between Windows and IANA time zone identifiers is the windowsZones.xml file, distributed as part of the Unicode CLDR project. The latest dev version can be found here.

However, CLDR is released only twice annually. This, along with the periodic cadence of Windows updates, and the irregular updates of the IANA time zone database, makes it complicated to just use the CLDR data directly. Keep in mind that time zone changes themselves are made at the whim of the world's various governments, and not all changes are made with sufficient notice to make it into these release cycles before their respective effective dates.

There are a few other edge cases that need to be handled that are not covered strictly by the CLDR, and new ones pop up from time to time. Therefore, I've encapsulated the complexity of the solution into the TimeZoneConverter micro-library, which can be installed from Nuget.

Using this library is simple. Here are some examples of conversion:

string tz = TZConvert.IanaToWindows("America/New_York");
// Result: "Eastern Standard Time"

string tz = TZConvert.WindowsToIana("Eastern Standard Time");
// result: "America/New_York"

string tz = TZConvert.WindowsToIana("Eastern Standard Time", "CA");
// result: "America/Toronto"

There are more examples on the project site.

It's important to recognize that while an IANA time zone can be mapped to a single Windows time zone, the reverse is not true. A single Windows time zone might be mapped to more than one IANA time zone. This can be seen in the above examples, where Eastern Standard Time is mapped to both America/New_York, and to America/Toronto. TimeZoneConverter will deliver the one that CLDR marks with "001", known as the "golden zone", unless you specifically provide a country code and there's a match for a different zone in that country.

Note: This answer has evolved over the years, so comments below may or may not apply to the current revision. Review the edit history for details. Thanks.

How to translate between windows and IANA timezones in java

I finally had to make my own implementation. The windowsZones.xml needs to be updated for plenty of missing timezone entries. I'm not publishing the updated file as there are many timezones where there is no perfect match between Windows offset & IANA offset.

Also, as for one Windows timezone there could be multiple IANA timezone. So, i had to make implementation to choose best suitable according to other information available like geography of user(address) etc.

With this, I'm just using the windowsZones.xml to get IANA timezone from Windows timezone & vice-versa.

IANA to Windows timezone mapping

It is very important that when we do the re-mapping, the actual offsets and DST flags do not change.

That's effectively requiring the Windows database and the IANA database to always be exactly in sync. While I can understand the desire, it's an unrealistic expectation. Aside from anything else, both databases change over time, as governments make changes to their rules. Unless you ensure that you change both versions at exactly the same time (on all machines you use!) there will always be the possibility of discrepancies. That's aside from the actual data being different in the stable state - which also happens.

If you look at the ICU mapping between Windows and IANA zones names (e.g. this copy in the Noda Time repo) you'll see that it's not a 1:1 mapping. A single Windows time zone ID can map to several different IANA IDs, with one (territory 001) being deemed the primary mapping.

I'd expect that for the vast majority of the time, you'll see the same results between the two - but it's definitely not guaranteed for every instant in every time zone.

Timezones abbreviations

A few things:

  • The list you pointed at is not the official list of Microsoft Windows time zones. It is a copy of a very old static list from Windows Embedded 1.1., which has long been deprecated. There presently is no actively maintained list of all Windows time zones on a Microsoft web page.

  • To get a list of Windows time zones, call TZUTIL /L on the command line. It will return the ID and display name of each time zone installed on the system.

  • If you look at the CLDR zone mapping file, you'll see that many Windows zones map to more than one IANA zone. If you simply map the Windows zone to the 001 "golden zone", you may end up picking an IANA abbreviation that doesn't apply for the user. Thus, if you take the approach you described (converting to IANA and taking the IANA abbreviation), be sure to take the country code into consideration as well when doing the mapping.

Also:

  • There is no official single list of time zone abbreviations anywhere, because time zone abbreviations are not standardized. Many of the abbreviations we might use in English don't necessarily apply to non-English speakers, and many time zones don't have abbreviations at all.

  • Even in English, many time zone abbreviations are contradictory or ambiguous.

Some examples of problematic time zone abbreviations:

  • Does CST mean Central Standard Time, Cuba Standard Time, or China Standard Time?
  • Does IST mean India Standard Time, Israel Standard Time, or Ireland Standard Time?
  • Should Hawaii use HST or HAST?
  • Should HNE (Heure Normale de l'Est) be used instead of EST (Eastern Standard Time) in Quebec, Canada since its official language is French?
  • What is the time zone abbreviation of Minsk, Belarus? You might think MSK, but that's offensive to some because that abbreviation is also commonly used for Moscow, Russia. Belarus has one time zone for the whole country, and they don't speak English there. IANA gives the abbreviation as simply the numeric UTC offset +03 (since mid 2011).

Because of the above problems...

  • There is no official list of time zone abbreviations for Windows time zones. Windows doesn't use them.

  • You might find some time zone abbreviations listed in CLDR data, and exposed with various libraries and APIs, but they only sparsely populated in the data set. CLDR has not been reliably collecting or maintaining time zone abbreviations.

Should I map Windows time zones to IANA time zones if I don't use noda time?

If your application implements .Net TimeZoneInfo, then you should probably just show Windows time zones via the DisplayName property of the TimeZoneInfo object, then store the corresponding Id property as the users's time zone selection.

On the other hand, if you were to expose a map-based time zone selection picker, such as this one or this one, then you could use their resulting IANA time zone ID to map to a Windows zone. But if you have no such need to this kind of UI, then don't bother with them.

noda time iana mapping of Etc/UTC to Windows timezone

As Jon pointed out, the CLDR mapping is not there for "Etc/UTC". Instead, the CLDR maps the Windows "UTC" time zone to "Etc/GMT". IMHO - this is in error.

The CLDR requires "stable identifiers", so it has not traditionally updated its mappings when time zone names change. Instead, one would normally follow the "links" in the time zone database to map to the canonical zone.

However - the TZDB doesn't consider "Etc/GMT" to be a link for "Etc/UTC". They are two distinct zones. There's also "Etc/UCT". This is so that applications that rely on the TZDB for time zone abbreviations can use their choice of abbreviation (GMT, UTC, or UCT). (See discussion here.)

Anyway - thanks for reminding us of this problem. I updated the mapping functions to take this into account.

Map windows time zones to Oracle time zones

Actually that's not possible. Oracle uses the IANA Time zone database. Try tzutil /l to get a list all time zones with alternative name.

Or have a look at How to translate between Windows and IANA time zones?

NB, instead of ALTER SESSION SET TIME_ZONE = ... you can also preset the Oracle session time zone by Environment variable ORA_SDTZ or in your Registry at

HKEY_LOCAL_MACHINE\SOFTWARE\Oracle\KEY_<Oracle Home>\ORA_SDTZ
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Oracle\KEY_<Oracle Home>_32bit\ORA_SDTZ


Related Topics



Leave a reply



Submit