In NodaTime, how do you find the long form name of a timezone given the tz timezone id?
For example, if I supply "America/Los_Angeles", I should get "Pacific Standard Time" back.
In NodaTime, how do you find the long form name of a timezone given the tz timezone id?
For example, if I supply "America/Los_Angeles", I should get "Pacific Standard Time" back.
TZDB itself doesn't hold descriptions for timezones: the timezone with ID
America/Los_Angeles
simply holds transitions with names such as "PDT" and "PST". So from that point of view, the data simply isn't there.That said, you can get the Windows timezone IDs that map to a given TZDB zone (originally from the CLDR
windowsZones.xml
data), and Windows generally does use names like "Pacific Standard Time" for its zone IDs.e.g.
However, there are some caveats with this approach:
Europe/Vienna
being an example of a TZDB zone that no Windows zone ID uses), but there's no reason in theory that you couldn't find two or more Windows zone IDs mapping to the same TZDB zone.Europe/London
is mapped from a Windows zone called "GMT Standard Time", which isn't a great string to show to a user.However, for what you're doing, this might be acceptable.
Short answer: https://github.com/barrycarter/bcapps/blob/master/ASTRO/tz2name.txt
Long answer: As others have noted, you can use CLDR's
common/supplemental/metaZones.xml
file to map timezones to regions. For example:maps the timezone "America/Barbados" to the region "Atlantic".
You can then use
common/main/en.xml
to convert the region to a timezone name. For example:tells us the names of the timezones (long and short forms) used in the "Atlantic" region.
This is pretty much a repeat of the other answers, but with direct references to files in question.
The information you need to produce the "long form" of a time zone name isn't in Noda Time, but it can be found in the CLDR.
I've recently put together a library called simply "Time Zone Names", that embeds the CLDR time zone names. You can use these with the IANA (TZDB) identifiers that are used by Noda Time time zones.
Simply pass the time zone and language, and it will provide the appropriate generic name, standard name, and daylight name. You can use Noda Time to decide which form is appropriate to display.
For the language, you can pass either a two digit code like
"en"
, or you can pass a fully regionalized version such as"en-US"
. This aligns withCultureInfo
names, so you can passCultureInfo.CurrentUICulture.Name
if you like.