Home All Groups Group Topic Archive Search About

Time zone information related to standardDate incorrect

Author
30 Nov 2006 9:36 PM
John K
Our .NET 2.0 server application needs to determine when daylight savings time
ends and starts for a particular time zone, which will not necessarily be the
time zone of the server.  Devices from various time zones call into the
server to update their local clocks (using server as master time keeper). 
Thus, once the server determines what time zone the device is in, the app.
iterates through "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Time Zones" and finds the information for the device's time
zone (i.e. via the binary TZI information).  The problem is that the data for
when the particular time zone switches in/out of daylight savings time is
incorrect.  Case in point, the registry indicates that October 8, 2006 is the
day the "(GMT-05:00) Eastern Time (US & Canada)" zone quits daylights savings
time. This is incorrect.  However, if I use the .NET
TimeZone.GetDaylightChanges method and supply the year 2006 for the current
zone (in this case the same zone), it returns October 29, which is correct. 
How do I get Windows 2003 to provide the date/time when daylight savings
starts/ends for a given time zone (again, which could be ANY zone).  The .NET
2.0 framework only retrieves this information for the current time zone.
Thus, apparently I need to resort to Windows API functions. In other words,
what is the .NET TimeZone.GetDaylightChanges function doing to the TZI data
to get the right date? Perhaps its related to the fact that it is different
for each year, thus it is probably a matter of calculating the date for a
year.
--
Thank you.

Author
1 Dec 2006 7:21 AM
Walter Wang [MSFT]
Hi,

You can use following class to get a time zone's DST start and end date:

#SimpleTimeZone .NET Framework Class
http://www.michaelbrumm.com/simpletimezone.html

Get both the SimpleTimeZone and Win32 TimeZones source code, and use
following code to test it:

        Dim st As SimpleTimeZone()
        st = Win32.TimeZones.GetTimeZones()
        For Each stz As SimpleTimeZone In st
            If stz.StandardName = "Eastern Standard Time" Then
                Dim dt As DaylightTime = stz.GetDaylightChanges(2006)
                Console.WriteLine(dt.Start)
                Console.WriteLine(dt.End)
            End If
        Next

If you need to run it on Vista, there's one place to change: there's no
"Index" registry value under each time zone, therefore you need to comment
out some code in the class. I've both tested it on Vista and XP, above test
code prints:

4/2/2006 2:00:00 AM
10/29/2006 2:00:00 AM

Let me know if this is what you wanted. Thanks.


Sincerely,
Walter Wang (waw***@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Author
1 Dec 2006 10:13 PM
John K
That worked.  Thank you very much.
--

Show quote
"John K" wrote:

> Our .NET 2.0 server application needs to determine when daylight savings time
> ends and starts for a particular time zone, which will not necessarily be the
> time zone of the server.  Devices from various time zones call into the
> server to update their local clocks (using server as master time keeper). 
> Thus, once the server determines what time zone the device is in, the app.
> iterates through "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
> NT\CurrentVersion\Time Zones" and finds the information for the device's time
> zone (i.e. via the binary TZI information).  The problem is that the data for
> when the particular time zone switches in/out of daylight savings time is
> incorrect.  Case in point, the registry indicates that October 8, 2006 is the
> day the "(GMT-05:00) Eastern Time (US & Canada)" zone quits daylights savings
> time. This is incorrect.  However, if I use the .NET
> TimeZone.GetDaylightChanges method and supply the year 2006 for the current
> zone (in this case the same zone), it returns October 29, which is correct. 
> How do I get Windows 2003 to provide the date/time when daylight savings
> starts/ends for a given time zone (again, which could be ANY zone).  The .NET
> 2.0 framework only retrieves this information for the current time zone.
> Thus, apparently I need to resort to Windows API functions. In other words,
> what is the .NET TimeZone.GetDaylightChanges function doing to the TZI data
> to get the right date? Perhaps its related to the fact that it is different
> for each year, thus it is probably a matter of calculating the date for a
> year.
> --
> Thank you.

AddThis Social Bookmark Button