Note: Different OS will have different Time Zone Id.
On Windows systems, FindSystemTimeZoneById
tries to match id
to the subkey names of the HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zones branch of the registry. On Linux and macOS, it uses time zone information available in the ICU Library
Windows OS
Pacific Standard Time
public static DateTime GetPacificStandardTime()
{
var utc = DateTime.UtcNow;
TimeZoneInfo pacificZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
var pacificTime = TimeZoneInfo.ConvertTimeFromUtc(utc, pacificZone);
return pacificTime;
}
Non Windows OS
America/Los_Angeles
public static DateTime GetPacificStandardTime()
{
var utc = DateTime.UtcNow;
TimeZoneInfo pacificZone = TimeZoneInfo.FindSystemTimeZoneById("America/Los_Angeles");
var pacificTime = TimeZoneInfo.ConvertTimeFromUtc(utc, pacificZone);
return pacificTime;
}
Time Zone List
https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
Code | UTC | Windows OS | Non Windows OS |
PST | UTC-8 | Pacific Standard Time | America/Los_Angeles |
MST | UTC-7 | Mountain Standard Time | America/Denver |
CST | UTC-6 | Central Standard Time | America/Chicago |
EST | UTC-5 | Eastern Standard Time | America/New_York |
Sources:
https://stackoverflow.com/questions/8862335/convert-local-time-zone-to-pst-time-zone-in-c-sharp
http://www.xiirus.net/articles/article-_net-convert-datetime-from-one-timezone-to-another-7e44y.aspx
https://docs.microsoft.com/en-us/dotnet/api/system.timezoneinfo.findsystemtimezonebyid?view=net-5.0
Comments