Results 1 to 2 of 2

Thread: Time Zone

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2000
    Posts
    39

    Talking

    Is there way to get Time Zone information and possibly change it using Windows API?

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Sure!
    Code:
    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 31) As Integer
      StandardDate As SYSTEMTIME
      StandardBias As Long
      DaylightName(0 To 31) As Integer
      DaylightDate As SYSTEMTIME
      DaylightBias As Long
    End Type
    Private Declare Function SetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
    Private Declare Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
    
    Public Function GetTimeZone() As String
        Dim tZone As TIME_ZONE_INFORMATION
        Dim lngRet As Long
        Dim i As Long
        Dim strBuffer As String
    
        lngRet = GetTimeZoneInformation(tZone)
        
        For i = 0 To 31  ' the array's range is from 0 to 31
            If tZone.StandardName(i) = 0 Then Exit For
            strBuffer = strBuffer & Chr(tZone.StandardName(i)) 'convert the ASCII code into a character
        Next
        
        GetTimeZone = strBuffer
    End Function
    
    
    Private Sub Command1_Click()
        MsgBox GetTimeZone
    End Sub
    To Set TimeZone information, you have to run SetTimeZoneInformation, passing the TIME_ZONE_INFORMATION structure with time zone you want. If you pass ivalid time zone name, the function will fail.

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