List of Timezone IDs for use with FindTimeZoneById() in C#?
Here's a full listing of a program and its results.
The code:
using System;
namespace TimeZoneIds
{
class Program
{
static void Main(string[] args)
{
foreach (TimeZoneInfo z in TimeZoneInfo.GetSystemTimeZones())
{
Console.WriteLine(z.Id);
}
}
}
}
The TimeZoneId results on my Windows 7 workstation:
Dateline Standard Time
UTC-11
Samoa Standard Time
Hawaiian Standard Time
Alaskan Standard Time
Pacific Standard Time (Mexico)
Pacific Standard Time
US Mountain Standard Time
Mountain Standard Time (Mexico)
Mountain Standard Time
Central America Standard Time
Central Standard Time
Central Standard Time (Mexico)
Canada Central Standard Time
SA Pacific Standard Time
Eastern Standard Time
US Eastern Standard Time
Venezuela Standard Time
Paraguay Standard Time
Atlantic Standard Time
Central Brazilian Standard Time
SA Western Standard Time
Pacific SA Standard Time
Newfoundland Standard Time
E. South America Standard Time
Argentina Standard Time
SA Eastern Standard Time
Greenland Standard Time
Montevideo Standard Time
UTC-02
Mid-Atlantic Standard Time
Azores Standard Time
Cape Verde Standard Time
Morocco Standard Time
UTC
GMT Standard Time
Greenwich Standard Time
W. Europe Standard Time
Central Europe Standard Time
Romance Standard Time
Central European Standard Time
W. Central Africa Standard Time
Namibia Standard Time
Jordan Standard Time
GTB Standard Time
Middle East Standard Time
Egypt Standard Time
Syria Standard Time
South Africa Standard Time
FLE Standard Time
Israel Standard Time
E. Europe Standard Time
Arabic Standard Time
Arab Standard Time
Russian Standard Time
E. Africa Standard Time
Iran Standard Time
Arabian Standard Time
Azerbaijan Standard Time
Mauritius Standard Time
Georgian Standard Time
Caucasus Standard Time
Afghanistan Standard Time
Ekaterinburg Standard Time
Pakistan Standard Time
West Asia Standard Time
India Standard Time
Sri Lanka Standard Time
Nepal Standard Time
Central Asia Standard Time
Bangladesh Standard Time
N. Central Asia Standard Time
Myanmar Standard Time
SE Asia Standard Time
North Asia Standard Time
China Standard Time
North Asia East Standard Time
Singapore Standard Time
W. Australia Standard Time
Taipei Standard Time
Ulaanbaatar Standard Time
Tokyo Standard Time
Korea Standard Time
Yakutsk Standard Time
Cen. Australia Standard Time
AUS Central Standard Time
E. Australia Standard Time
AUS Eastern Standard Time
West Pacific Standard Time
Tasmania Standard Time
Vladivostok Standard Time
Central Pacific Standard Time
New Zealand Standard Time
UTC+12
Fiji Standard Time
Kamchatka Standard Time
Tonga Standard Time
.NET Core How to get all timezones + info in an OS-independent way
Using TimeZoneConverter, the following will return consistent results on any platform:
This will give you the current UTC offset of any time zone. The
id
can be either those from either OS:TimeZoneInfo tz = TZConvert.GetTimeZoneInfo(id);
TimeSpan offset = tz.GetUtcOffset(DateTime.UtcNow);This will list all of the Windows time zone IDs:
var list = TZConvert.KnownWindowsTimeZoneIds;
This will list all of the IANA time zone names:
var list = TZConvert.KnownIanaTimeZoneNames;
You might also be interested in using TimezoneNames to offer a human-readable list of display names, though it can't yet offer the exact Windows display name that you would see from TimeZoneInfo.DisplayName
on Windows. That functionality is on the backlog.
TimeZoneInfo Id is dependent on machines?
While it is possible that the ID won't be found (see the other answers), if both machines have current Windows Updates, then it is not likely you will have a mismatch.
Even then, while changes to the definitions for daylight saving time and display names occur multiple times per year, it is rare for entirely new time zones to be created, and the IDs will never change once established.
So as long as at least your server has the current Windows Updates for time zones, then you should be able to handle any valid input from the clients, even if they aren't as up to date. You can review all the time zone updates for Windows on this site.
However, despite all of this, my best advice would be to give up using Microsoft time zones and use standard IANA time zones instead. See the timezone tag wiki for details. In .NET, the best way to achieve this is by using the Noda Time library.
Select only United State Time Zones
There's little point trying to drink from the fire hose here. Just ask for the ones you want explicitly:
var zones = new List<TimeZoneInfo> {
TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"),
TimeZoneInfo.FindSystemTimeZoneById("Mountain Standard Time"),
TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"),
TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")
};
Don't forget Hawaii and Alaska :)
Missing 'Mountain Standard Time' timezone when using FindTimeZoneById() c# on mac
The IDs and data used with TimeZoneInfo
are platform dependent:
- On Windows, the IDs are the Microsoft time zone identifiers, as used with the
tzutil.exe
command, Win32 APIs, and are sourced from the Registry.- Example:
"Mountain Standard Time"
- Example:
- On Mac OSX, Linux, and other non-Windows platforms, the IDs are IANA time zone identifiers, as used by the
TZ
environment variable,timedatectl
,sudo dpkg-reconfigure tzdata
,sudo systemsetup -settimezone timezone
, and other platform-specific utilities. The data is sourced from the IANA tz database.- Example:
"America/Denver"
- Example:
Thus you can change your code to the following, which will run on Linux and Mac OSX.
TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("America/Denver");
If you cannot change the identifiers used in your application, or are designing your application to be cross-platform and need to work with both sets of identifiers, then use my TimeZoneConverter library:
// Either of these will work on any platform
TimeZoneInfo tzi = TZConvert.GetTimeZoneInfo("Mountain Standard Time");
TimeZoneInfo tzi = TZConvert.GetTimeZoneInfo("America/Denver");
See also the "Time Zone Databases" section of the timezone tag wiki.
TimeZoneInfo.FindSystemTimeZoneById() not working for Gulf Standard Time
As pointed out in comments, "Gulf Standard Time"
isn't a valid Windows time zone identifier.
Gulf Standard Time usually refers to UTC+04:00 with no DST, as observed in the United Arab Emirates and Oman, as described here. The corresponding time zone in Windows appears with an English display name of (UTC+04:00) Abu Dhabi, Muscat
, and has a corresponding ID of Arabian Standard Time
.
Thus in .NET:
TimeZoneInfo tZone = TimeZoneInfo.FindSystemTimeZoneById("Arabian Standard Time");
Console.WriteLine(tzone.DisplayName);
// prints: (UTC+04:00) Abu Dhabi, Muscat
To get a list of supported time zones, use TimeZoneInfo.GetSystemTimeZones()
in your .NET code, and examine the Id
and DisplayName
properties. Alternatively, you can call TZUTIL /L
on the command line to list them.
Also, just to point out that this all assumes you are running on Windows. If you are actually running .NET Core on non-Windows systems (Linux, OSX, etc.), then you should uses IANA time zone IDs. In this case, either "Asia/Dubai"
, or "Asia/Muscat"
would be appropriate.
And if your code might run both on Windows and Non-Windows systems, then you will need to take advantage of my TimeZoneConverter library.
Related Topics
Regular Expression for Finding 'Href' Value of a <A> Link
Start a .Net Process as a Different User
Copying from and to Clipboard Loses Image Transparency
Remove Weird Characters ( a with Hat) from SQL Server Varchar Column
Why File.Readalllinesasync() Blocks the UI Thread
How to Pass a Value from a Child Back to the Parent Form
Run Single Instance of an Application Using Mutex
How to Detect If Console.In (Stdin) Has Been Redirected
Update .Net Web Service to Use Tls 1.2
Xml Serialization of Interface Property
Convert a List to a String in C#
Execute C# Code at Runtime from Code File