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);
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…