Reading time zone and daylight info? 
Author Message
 Reading time zone and daylight info?

In Win98SE, using Visual Studio 6 (either Visual C++ or Visual Basic) I
am trying to figure out a way to read the system's time zone (Eastern,
Central, etc.) and whether daylight savings time is in effect.  In C++
the calls to check the time zone apparently depend on the "TZ" parameter
being set.  If it is not, I would that there is a way to read the time
zone information that I or any user sets via the Control Panel.

Any ideas?

Thanks.

Best regards,

Thomas Knapp



Thu, 10 Jun 2004 06:16:29 GMT  
 Reading time zone and daylight info?

        Take a look at the GetTimeZoneInformation(..) API function.

Cheers
Check Abdoul
------------------


Quote:
> In Win98SE, using Visual Studio 6 (either Visual C++ or Visual Basic) I
> am trying to figure out a way to read the system's time zone (Eastern,
> Central, etc.) and whether daylight savings time is in effect.  In C++
> the calls to check the time zone apparently depend on the "TZ" parameter
> being set.  If it is not, I would that there is a way to read the time
> zone information that I or any user sets via the Control Panel.

> Any ideas?

> Thanks.

> Best regards,

> Thomas Knapp



Thu, 10 Jun 2004 06:42:56 GMT  
 Reading time zone and daylight info?

Quote:
>In Win98SE, using Visual Studio 6 (either Visual C++ or Visual Basic) I
>am trying to figure out a way to read the system's time zone (Eastern,
>Central, etc.) and whether daylight savings time is in effect.  In C++
>the calls to check the time zone apparently depend on the "TZ" parameter
>being set.  If it is not, I would that there is a way to read the time
>zone information that I or any user sets via the Control Panel.

Thomas,

Try the GetTimeZoneInformation API.

Merry Christmas
Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Thu, 10 Jun 2004 07:35:26 GMT  
 Reading time zone and daylight info?
Thomas,

You can use the GetTimeZoneInformation API function. In the code below, the
function TimeZoneName will return the name of the time zone as a string (e.g.,
"Central Standard Time"), and the function IsDaylightTime will return a boolean
indicating whether you are currently in Daylight Savings time.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC

'''''''''''''''''''''''''''''''''''''''''''''''''
Private Declare Function GetTimeZoneInformation Lib "kernel32" _
    (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long

Private 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

Private Type TIME_ZONE_INFORMATION
        Bias As Long
        StandardName(31) As Integer
        StandardDate As SYSTEMTIME
        StandardBias As Long
        DaylightName(31) As Integer
        DaylightDate As SYSTEMTIME
        DaylightBias As Long
End Type

Public Enum cstDSTType
    cstDSTUnknown = 0
    cstDSTStandard = 1
    cstDSTDaylight = 2
End Enum

Private TZInfo As TIME_ZONE_INFORMATION
Private TZType As cstDSTType

Function TimeZoneName() As String

    TZType = GetTimeZoneInformation(TZInfo)

    If TZType = cstDSTStandard Then
        TimeZoneName = StringFromIntArray(TZInfo.StandardName)
    ElseIf TZType = cstDSTDaylight Then
        TimeZoneName = StringFromIntArray(TZInfo.DaylightName)
    Else
        TimeZoneName = "Unknown"
    End If

End Function

Function IsDaylightTime() As Boolean
    TZType = GetTimeZoneInformation(TZInfo)
    IsDaylightTime = (TZType = cstDSTDaylight)
End Function

Private Function StringFromIntArray(IntArray() As Integer) As String
'
' The time zone names are returned from Windows as an array of
' integers.  The function converts that to a string.
'
Dim Ndx As Long
Dim C As String
Do Until IntArray(Ndx) = 0
    C = C & Chr(IntArray(Ndx))
    Ndx = Ndx + 1
Loop
StringFromIntArray = C

End Function
'''''''''''''''''''''''''''''''''''''''''''''''''


Quote:
> In Win98SE, using Visual Studio 6 (either Visual C++ or Visual Basic) I
> am trying to figure out a way to read the system's time zone (Eastern,
> Central, etc.) and whether daylight savings time is in effect.  In C++
> the calls to check the time zone apparently depend on the "TZ" parameter
> being set.  If it is not, I would that there is a way to read the time
> zone information that I or any user sets via the Control Panel.

> Any ideas?

> Thanks.

> Best regards,

> Thomas Knapp



Fri, 11 Jun 2004 00:42:44 GMT  
 Reading time zone and daylight info?
I should have added that if you use the "Windows API Viewer" to get the
definition of TIME_ZONE_INFORMATION, it will give you the wrong sizes for the
StandardName and DaylightName arrays.

The Windows API Viewer creates

StandardName(32) As Integer
DaylightName(32) As Integer

You MUST change these to

StandardName(31) As Integer
DaylightName(31) As Integer

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC


Quote:
> Thomas,

> You can use the GetTimeZoneInformation API function. In the code below, the
> function TimeZoneName will return the name of the time zone as a string (e.g.,
> "Central Standard Time"), and the function IsDaylightTime will return a
boolean
> indicating whether you are currently in Daylight Savings time.

> --
> Cordially,
> Chip Pearson
> Microsoft MVP - Excel
> Pearson Software Consulting, LLC

> '''''''''''''''''''''''''''''''''''''''''''''''''
> Private Declare Function GetTimeZoneInformation Lib "kernel32" _
>     (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long

> Private 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

> Private Type TIME_ZONE_INFORMATION
>         Bias As Long
>         StandardName(31) As Integer
>         StandardDate As SYSTEMTIME
>         StandardBias As Long
>         DaylightName(31) As Integer
>         DaylightDate As SYSTEMTIME
>         DaylightBias As Long
> End Type

> Public Enum cstDSTType
>     cstDSTUnknown = 0
>     cstDSTStandard = 1
>     cstDSTDaylight = 2
> End Enum

> Private TZInfo As TIME_ZONE_INFORMATION
> Private TZType As cstDSTType

> Function TimeZoneName() As String

>     TZType = GetTimeZoneInformation(TZInfo)

>     If TZType = cstDSTStandard Then
>         TimeZoneName = StringFromIntArray(TZInfo.StandardName)
>     ElseIf TZType = cstDSTDaylight Then
>         TimeZoneName = StringFromIntArray(TZInfo.DaylightName)
>     Else
>         TimeZoneName = "Unknown"
>     End If

> End Function

> Function IsDaylightTime() As Boolean
>     TZType = GetTimeZoneInformation(TZInfo)
>     IsDaylightTime = (TZType = cstDSTDaylight)
> End Function

> Private Function StringFromIntArray(IntArray() As Integer) As String
> '
> ' The time zone names are returned from Windows as an array of
> ' integers.  The function converts that to a string.
> '
> Dim Ndx As Long
> Dim C As String
> Do Until IntArray(Ndx) = 0
>     C = C & Chr(IntArray(Ndx))
>     Ndx = Ndx + 1
> Loop
> StringFromIntArray = C

> End Function
> '''''''''''''''''''''''''''''''''''''''''''''''''



> > In Win98SE, using Visual Studio 6 (either Visual C++ or Visual Basic) I
> > am trying to figure out a way to read the system's time zone (Eastern,
> > Central, etc.) and whether daylight savings time is in effect.  In C++
> > the calls to check the time zone apparently depend on the "TZ" parameter
> > being set.  If it is not, I would that there is a way to read the time
> > zone information that I or any user sets via the Control Panel.

> > Any ideas?

> > Thanks.

> > Best regards,

> > Thomas Knapp



Fri, 11 Jun 2004 01:09:52 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Daylight and Time Zone informations

2. How to Retrieve Daylight and Time Zone informations

3. How to convert local time with specific time zone to UTC time in Win32 API

4. Time: UCT, local time, daylight - any standards?

5. Time: UCT, local time, daylight - any standards?

6. standard c library time.h and daylight savings time

7. Time: UCT, local time, daylight - any standards?

8. How to convert local time to gmt using a local variable time zone per process/thread

9. set date/time/time zone dialog

10. Real time From Time Zone information

11. Read/Write Properties During Design Time, but Read-Only During Run-Time

12. A question about time function and daylight saving.

 

 
Powered by phpBB® Forum Software