I have an app with some date time zone formats mentioned in the DB which are like "Europe/Rome" , "Europe/Berlin", Is there a way to find out TimezoneId's using this timezone formats?
-
Short answer: No, not using any built-in .NET APIs. – mm8 Jan 02 '20 at 15:53
-
See the linked duplicate for how to do this. Jon's answer is also good. But I assume by `Europe/Germany` in your title you actually meant `Europe/Berlin`, as the former is not a valid IANA time zone ID. – Matt Johnson-Pint Jan 02 '20 at 17:43
1 Answers
When running on Windows, TimeZoneInfo
uses the Windows time zone database, rather than the IANA time zone database which uses IDs of the form "Europe/Rome" etc.
While you could look for Windows time zone IDs containing the city name (as suggested in other answers), there's absolutely no guarantee that you'll always find such an ID, and I would recommend against doing so. Even if you find the right TimeZoneInfo
, it won't necessarily have the same rules as the IANA database.
Instead, I'd recommend use a third-party library that supports the IANA time zone database. I maintain one such library, Noda Time, which is a whole alternative date/time API for .NET - but with conversions to and from DateTime
and DateTimeOffset
if you really need them. Other libraries also exist that use the IANA time zone database, but I believe Noda Time is the most widely adopted one.
If you really need to use TimeZoneInfo
, you could use Noda Time to find the Windows IDs that match it most closely using TzdbDateTimeZoneSource.WindowsMapping
in the 2.x version, or if you're using 3.x (currently in beta) there's TzdbDateTimeZoneSource.TzdbToWindowsIds
to make life simpler.

- 1,421,763
- 867
- 9,128
- 9,194