Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use GetTimeZoneInformation api function 1

Status
Not open for further replies.

evalesthy

Programmer
Oct 27, 2000
513
US
Could I use this windows API to tell me what time zone a user pc is in? I want to write TimeZone value (Eastern, Mountain, Pacific, etc) to table along with Time and Date stamps that I already have. If so, how would I call this function to fill in TimeZone in a text box on form?
 
this is based on info from vbapi.com
Place this code in a new module

Option Compare Database
Option Explicit

Declare Function GetTimeZoneInformation Lib "kernel32.dll" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
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
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

Function fGetTimeZone() As String
Dim tzi As TIME_ZONE_INFORMATION ' receives information on the time zone
Dim c As Long ' counter variable needed to display time zone name
Dim retVal As Long
Dim strZone As String
retVal = GetTimeZoneInformation(tzi)
' Oddly, instead of being stored in a string, the time zone name is stored in a
' 32-element array, each element holding the ASCII code of one of the characters.
' This loop converts the array into a readable string.

For c = 0 To 31 ' the array's range is from 0 to 31
If tzi.StandardName(c) = 0 Then Exit For ' abort if the terminating null character is reached
strZone = strZone & Chr(tzi.StandardName(c)) ' convert the ASCII code into a character and display it
Next c


fGetTimeZone = strZone ' read information on the computer's selected time zone


End Function


Then you can just call the Function to get the zone, try it using a messagebox

MsgBox "Time Zone is " & fGetTimeZone

PaulF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top