Results 1 to 5 of 5

Thread: Time Zone Information API

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Posts
    90

    Time Zone Information API

    I have two questions relating to the Time Zone Info API;

    1. how do I get the "current" time zone setting, and

    2. standard & daylight dates are relative dates .. relative to what?

    Thank you in advance, Bob.

  2. #2
    jim mcnamara
    Guest
    Code:
    Private Const TIME_ZONE_ID_UNKNOWN As Long = 1
    Private Const TIME_ZONE_ID_STANDARD As Long = 1
    Private Const TIME_ZONE_ID_DAYLIGHT As Long = 2
    Private Const TIME_ZONE_ID_INVALID As Long = &HFFFFFFFF
    
    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(0 To ((32 * 2) - 1)) As Byte
       StandardDate As SYSTEMTIME
       StandardBias As Long
       DaylightName(0 To ((32 * 2) - 1)) As Byte
       DaylightDate As SYSTEMTIME
       DaylightBias As Long
    End Type
    
    Private Declare Function GetTimeZoneInformation Lib "kernel32" _
        (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
    
    
    
    Private Sub Command1_Click()
       Dim tmp
       tmp = Format$(Now, "hh:mm:ss AMPM")
       Text1.Text = tmp & " " & GetCurrentTimeZone()
    
    
    End Sub
    
    
    Private Function IsDaylightSavingTime() As Boolean
    
       Dim tzi As TIME_ZONE_INFORMATION
    
       IsDaylightSavingTime = GetTimeZoneInformation(tzi) = TIME_ZONE_ID_DAYLIGHT
    
    End Function
    
    
    Private Function GetCurrentTimeZone() As String
    
       Dim tzi As TIME_ZONE_INFORMATION
       Dim tmp As String
       Dim pos As Integer
       Select Case GetTimeZoneInformation(tzi)
          Case 0:  tmp = "Cannot determine current time zone"
          Case 1:  tmp = tzi.StandardName
          Case 2:  tmp = tzi.DaylightName
       End Select
       pos = InStr(tmp, Chr$(0))
       If pos Then
             tmp = Left$(tmp, pos - 1)
        Else
             tmp = item
        End If
      
       GetCurrentTimeZone = tmp
       
    End Function
    Daylight and standard time zones are set relative to your longitude - how far West or East you are from GMT (Greenwich Mean Time). 15 degrees of longitude is one hour - so most time zones are about that wide. Some time zones are on a 7.5 degree boundary - Macao for instance.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Posts
    90
    Jim

    From this code segment;

    Select Case GetTimeZoneInformation(tzi)
    Case 0: tmp = "Cannot determine current time zone"
    Case 1: tmp = tzi.StandardName
    Case 2: tmp = tzi.DaylightName
    End Select

    am I correct to assume that the API returns 0 if unsuccessful, 1 if standard time in use and 2 if daylight time in use? If so, this isn't in my documentation.

  4. #4
    jim mcnamara
    Guest
    I believe it is correct, since it has worked for a long time...


  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Posts
    90
    Thanks Jim, Bob.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width