Search code examples
c#.nettimezone

Timezone Abbreviations


TimeZoneInfo does not provide abbreviation or a short name for a given Timezone. The only good way to do it is to have a dictionary that will map abbreviations to either Timezone.id, StandardName or DaylightName properties. However, all the sources I searched for list of abbreviations have different timezone names, i.e. not the same as in Windows.

How do you show a user not a full name, id or any other name in .NET? I don't want the UtcOffset but Timezone abbreviation - PST for Pacific, UTC - for Universal, EST - for Eastern Standard and etc. Is there any C# compatible list or database with all possible timezones and their abbreviations that compatible with those that TimeZoneInfo.GetSystemTimeZones() gives you?


Solution

  • This is a tricky requirement, the best you can do is get the list of your choice and create a extension / helper method to get the abbreviation for the given TimeZoneInfo.

    Once place to start is at http://www.timeanddate.com/library/abbreviations/timezones/ which has a version of list which covers the zones I am aware of.

    The issue would be in selecting an appropriate abbreviation where more than one exists for a given timezone. For example UTC can be represented as UTC or WET (Western European Time) or WEZ (Westeuropäische Zeit) or WT (Western Sahara Standard Time).

    You may want to agree with your stakeholders on the naming convention you are going to follow with the given choices.