Visual Basic Locale/Regionalization Routines
GetTimeZoneInformation: Locale Standard and Daylight Time Zone Names
     
Posted:   Sunday April 08, 2001
Updated:   Monday December 26, 2011
     
Applies to:   VB4-32, VB5, VB6
Developed with:   VB5, Windows 2000
OS restrictions:   None
Author:   VBnet - Randy Birch, Chip Pearson, Bob Butler
     

Related:  

SetLocaleInfo: Change System Long and Short Date Formats
WM_TIMECHANGE: Detect System Changes to the Date/Time
RegQueryValueEx: Identify Time Zones by Time Zone Bias
EnumDateFormats: Regional Locale Date Settings
EnumTimeFormats: Regional Locale Time Settings
GetLocaleInfo: Regional Locale Date Settings
     
 Prerequisites
None.

Two simple functions that return only the names for the local daylight and standard zones.

Based on newsgroup postings by Bob Butler and Excel MVP Chip Pearson.

 BAS Module Code
None.

 Form Code
Add a label (Label1) for the current date, a command button (Command1) and two text boxes (Text1 - Text2) to a form. Other labels are optional. Add the following code:

Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
'               applications, but you may not reproduce 
'               or publish this code on any web site,
'               online service, or distribute as source 
'               on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
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 63) As Byte  'unicode (0-based)
   StandardDate As SYSTEMTIME
   StandardBias As Long
   DaylightName(0 To 63) As Byte  'unicode (0-based)
   DaylightDate As SYSTEMTIME
   DaylightBias As Long
End Type

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



Private Sub Form_Load()

   Command1.Caption = "Get Time Zone Names"
   
End Sub


Private Sub Command1_Click()

   Label1.Caption = Format$(Now, "long date")
   Text1.Text = GetStandardName()
   Text2.Text = GetDaylightName()

End Sub


Private Function GetDaylightName() As String

   Dim tzi As TIME_ZONE_INFORMATION
   Dim tmp As String

   Call GetTimeZoneInformation(tzi)
   tmp = tzi.DaylightName
   
   GetDaylightName = TrimNull(tmp)

End Function


Private Function GetStandardName() As String

   Dim tzi As TIME_ZONE_INFORMATION
   Dim tmp As String

   Call GetTimeZoneInformation(tzi)
   tmp = tzi.StandardName
   
   GetStandardName = TrimNull(tmp)
   
End Function


Private Function TrimNull(item As String)

    Dim pos As Integer
   
   'double check that there is a chr$(0) in the string  
    pos = InStr(item, Chr$(0))      
    If pos Then
       TrimNull = Left$(item, pos - 1)
    Else
       TrimNull = item
    End If
  
End Function
 Comments

 
 

PayPal Link
Make payments with PayPal - it's fast, free and secure!

 
 
 
 

Copyright ©1996-2011 VBnet and Randy Birch. All Rights Reserved.
Terms of Use  |  Your Privacy

 

Hit Counter