Reputation: 3334
I've been searching high and low and can't find an answer to this. How come the TZIs are different??
I've done some digging on MSDN and seen this: http://msdn.microsoft.com/en-us/library/system.timezoneinfo.findsystemtimezonebyid.aspx
Which explicitly states:
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 under Windows XP and Windows Vista. This branch does not necessarily contain a comprehensive list of time zone identifiers.
So I assume that means it's going to the registry every time?
But then this confuses the issue: http://msdn.microsoft.com/en-us/library/system.timezoneinfo.utc.aspx
And says:
This is a built-in object; information about this TimeZoneInfo object is not retrieved from the registry.
So it appears my call to FindSystemTimeZoneById()
is actually short circuiting and returning TimeZoneInfo.UTC, and not going to the registry at all! This is not idea though because I want the other version's DisplayName. What gives???
Upvotes: 1
Views: 7018
Reputation: 941208
This quirk is explained because of the different ways you searched for the timezone. The top one with the full name came from the registry and started life by you using GetSystemTimeZones(), it enumerates the registry keys.
The bottom one was produced by FindSystemTimeZoneById(), it has a short-cut:
public static TimeZoneInfo FindSystemTimeZoneById(string id)
{
if (string.Compare(id, "UTC", StringComparison.OrdinalIgnoreCase) == 0)
{
return Utc;
}
// etc..
}
So you get the pre-baked one with the short name.
Upvotes: 2