Home All Groups Group Topic Archive Search About

TimeZone.CurrentTimeZone doesn't update

Author
15 Nov 2006 7:27 AM
Dave Kane [MVP - Outlook]
I'm seeing TimeZone.CurrentTimeZone accurately reflecting the machine time
zone at the point that the assembly loads, but if the user subsequently
changes the Windows time zone the value of TimeZone.CurrentTimeZone doesn’t
change to reflect that.
In other words, if the system is on PST when my assembly loads then whenever
time I instantiate a TimeZone object
(System.TimeZone tz = System.TimeZone.CurrentTimeZone;)
the value of tz.StandardName returns "Pacific Standard Time" and
tz.GetUtcOffset comes back as -08:00:00 - even if I change to Brisbane time
(+10:00:00)

Is there some trick to this that I'm missing?

I've got an Outlook add-in that's passing date values to a web service. Even
though it works in UTC internally, the SOAP proxy classes expect values in
local time to which the parser then assigns an offset. The conversions to and
from UTC continue to use the original offset even if the user changes time
zones, which corrupts the data.

Author
16 Nov 2006 10:39 AM
Ciaran O''Donnell
The cultureinfo is cached when retrieved from windows. Call the following
function to empty the cache. This will cause things like the timezone to be
reloaded:
System.Globalization.CultureInfo.CurrentCulture.ClearCachedData();

Ciaran O'Donnell

Show quote
"Dave Kane [MVP - Outlook]" wrote:

> I'm seeing TimeZone.CurrentTimeZone accurately reflecting the machine time
> zone at the point that the assembly loads, but if the user subsequently
> changes the Windows time zone the value of TimeZone.CurrentTimeZone doesn’t
> change to reflect that.
> In other words, if the system is on PST when my assembly loads then whenever
> time I instantiate a TimeZone object
> (System.TimeZone tz = System.TimeZone.CurrentTimeZone;)
> the value of tz.StandardName returns "Pacific Standard Time" and
> tz.GetUtcOffset comes back as -08:00:00 - even if I change to Brisbane time
> (+10:00:00)
>
> Is there some trick to this that I'm missing?
>
> I've got an Outlook add-in that's passing date values to a web service. Even
> though it works in UTC internally, the SOAP proxy classes expect values in
> local time to which the parser then assigns an offset. The conversions to and
> from UTC continue to use the original offset even if the user changes time
> zones, which corrupts the data.
>

AddThis Social Bookmark Button