Reputation: 44075
On Windows 7. I am in PST TimeZone. I changed the timezone in Windows to Eastern and then executed this in LinqPad:
TimeZoneInfo tzinfo = TimeZoneInfo.Local;
tzinfo.Dump();
TimeZone localZone = TimeZone.CurrentTimeZone;
localZone.Dump();
Why is it not showing Eastern timezone and why one structure is showing Pacific timezone and the other Eastern?
Upvotes: 0
Views: 353
Reputation: 241420
.NET Caches the local time zone. If you need to be sure that you account for changes the user may have made, you need to call TimeZoneInfo.ClearCachedData()
before getting the local time zone.
From the MSDN docs (emphasis mine):
Cached time zone data includes data on the local time zone, the Coordinated Universal Time (UTC) zone, and any time zones that are retrieved by using methods such as
FindSystemTimeZoneById
andGetSystemTimeZones
.You might call the
ClearCachedData
method to reduce the memory devoted to the application's cache of time zone information or to reflect the fact that the local system's time zone has changed.
This probably applies within LinqPad also.
Upvotes: 1