I'm coding something that needs to change GMT to local time. Since Daylight Savings Time starts on the first Sunday in April and ends on the last Sunday in October, how can I determine if the date is within Daylight Savings Time?
You also need to know where you are. States like Arizona don't use daylight savings time, and countries in Europe go to DST on dates other than the first Sunday in April.
You can call a Win32 API function to find out this info.
[tt]
Public Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Public Type TIME_ZONE_INFORMATION
Bias As Long
StandardName(32) As Integer
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(32) As Integer
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type
Public Declare Function GetTimeZoneInformation Lib "kernel32" Alias "GetTimeZoneInformation" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
[/tt]
After calling the GetTimeZoneInformation function, examine the DaylightDate structure to find out when the change to daylight savings begins, and examine the StandardDate structure to find out when the change from daylight savings begins.
Is it possible to pass a date to the GetTimeZoneInformation function and then look at the DaylightName structure to see if that date was within Daylight Savings Time? I can only seem to get it to return the current time.
The GetTimeZoneInformation call will only tell you when daylight savings time begins and ends. You'll need to do a call to DateDiff to see if your date falls into that range (a negative result might mean you're on standard time).
You'll have to reformat the SYSTEMTIME structure into a normal VB Date datatype variable first, of course.
You didn't say exactly what your program was doing but if it's getting GMT/UTC from a time service to set your local clock there is an easy way without having to use timezone or daylight corrections:
Declare Function SetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME) As Long
Also broadcast this to Windows so the system tray clock gets updated immediately using:
SendMessage HWND_TOPMOST, WM_TIMECHANGE, 0&, ByVal 0
If you need more info send an e-maildgs@natallink.com.br).
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.