I would like to have a list of all the time zones available on a Windows Machine. How can I do this in .NET?
I know about the TimeZoneInfo.GetSystemTimeZones method, but this returns only the currently selected time zone(s)
DateTimeOffset current = DateTimeOffset.Now; ReadOnlyCollection<TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones(); Console.WriteLine("You might be in the following time zones:"); foreach (TimeZoneInfo timeZoneInfo in timeZones) { // Compare offset with offset for that date in that time zone if (timeZoneInfo.GetUtcOffset(current).Equals(current.Offset)) { Console.WriteLine(" {0}", timeZoneInfo.DisplayName); } }
Reference to a specific time and zone would follow standard guidelines with the zone in parentheses: 4:42 p.m. (PST), 11:03 a.m. (MDT), 2:30 p.m. (CST), 10:00 P.M. (EST). AP on the other hand advises to capitalize the full name of each time zone: Pacific/Mountain/Central/Eastern Standard Time.
The world is divided into 24 time zones.
No it doesn't, it returns every time zone the Windows machine knows about (in my installation, that's 91). The if statement you have there is what is limiting your output. Take that out but leave the Console.WriteLine part, and you'll see all 91 (or so) timezones.
e.g.
ReadOnlyCollection<TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones(); foreach (TimeZoneInfo timeZoneInfo in timeZones) Console.WriteLine("{0}", timeZoneInfo.DisplayName); That should write out 91 timezones to your console.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With