GetTimeZoneInfo




' Found on the Net Somewhere - Author : Bob Butler

'

'

'The following code demonstrates how to find the current time zone name

'and GMT offset:


Option Explicit

' Time Zone API declarations



Private Const TIME_ZONE_ID_UNKNOWN = 0
Private Const TIME_ZONE_ID_STANDARD = 1
Private Const TIME_ZONE_ID_INVALID = &HFFFFFFFF
Private Const TIME_ZONE_ID_DAYLIGHT = 2
Private Type SYSTEMTIME
wYear(1 To 2) As Byte ' VB pads integers
wMonth(1 To 2) As Byte ' so we use bytes
wDayOfWeek(1 To 2) As Byte
wDay(1 To 2) As Byte
wHour(1 To 2) As Byte
wMinute(1 To 2) As Byte
wSecond(1 To 2) As Byte
wMilliseconds(1 To 2) As Byte
End Type

Private Type TIME_ZONE_INFORMATION
bias As Long ' current offset to GMT
StandardName(1 To 64) As Byte ' unicode string
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(1 To 64) As Byte
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type

Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
Private Declare Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long

Private Sub Form_Load()
Dim x As Long ' scratch
Dim tzi As TIME_ZONE_INFORMATION
Dim dtNow As Date ' current system time
Dim dtGMT As Date ' current GMT time
Dim strName As String ' current tz name
Dim strInfo As String ' scratch

Select Case GetTimeZoneInformation(tzi)
' if not daylight assume standard

Case TIME_ZONE_ID_DAYLIGHT:
strName = tzi.DaylightName ' convert to string
Case Else:
strName = tzi.StandardName
End Select

' name terminates with null


x = InStr(strName, vbNullChar)

If x > 0 Then strName = Left$(strName, x - 1)

dtNow = Now ' get time
dtGMT = DateAdd("n", tzi.bias, dtNow) ' calculate GMT
' build string to display info

strInfo = "Time Zone: " & strName & vbCrLf & _
"Local time: " & Format$(dtNow, "dd-mmm-yyyy hh:mm:ss") & vbCrLf & _
"GMT offset: " & CStr(tzi.bias \ 60) & " hours, " & _
CStr(tzi.bias Mod 60) & " minutes" & vbCrLf & _
"GMT time: " & Format$(dtGMT, "dd-mmm-yyyy hh:mm:ss") & vbCrLf

MsgBox strInfo

End Sub










( gettimezoneinfo.html )- by Paolo Puglisi - Modifica del 17/12/2023