I've got an odd problem I can't seem to resolve. When I call TimeZoneInfo.GetSystemTimeZones
on my Win 7 x64 machine I get 101 results. When I call TimeZoneInfo.FindSystemTimeZoneById
on each of these and pass the StandardName attribute of the TimeZoneInfo object, 3 of them throw TimeZoneNotFoundException.
Here's a sample:
var tzs = TimeZoneInfo.GetSystemTimeZones();
foreach (var timeZoneInfo in tzs.OrderBy(t => t.BaseUtcOffset))
{
try
{
TimeZoneInfo.FindSystemTimeZoneById(timeZoneInfo.StandardName);
}
catch (TimeZoneNotFoundException)
{
Console.WriteLine(timeZoneInfo.DisplayName + "|" + timeZoneInfo.StandardName + "|" + timeZoneInfo.BaseUtcOffset);
}
}
Console.ReadLine();
This has trouble finding "Coordinated Universal Time", "Jerusalem Standard Time" and "Malay Peninsula Standard Time". Taking a case like Malaysia, I can see an entry for it when I look at the available time zones in my regional settings, although it's showing the DisplayName attribute rather than the StandardName:
However, I can't see it under either name when browsing the registry at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones
What's going on here? Why can't the Malaysia time zone be loaded by name?
Please no alternative time zone implementations using other libraries - I just want to get to the bottom of this issue for now. Thanks!
TimeZoneInfo.FindSystemTimeZoneById
method accepts the time zone id as parameter. You're using timeZoneInfo.StandardName
instead.
It seems, that for these 3 zones values for TimeZoneInfo.StandardName
and TimeZoneInfo.Id
properties are different. Using this:
TimeZoneInfo.FindSystemTimeZoneById(timeZoneInfo.Id);
will solve the issue.
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