Sunday, June 17, 2012

Memperoleh Informasi Time Zone Dari Local Time

Option Explicit

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(32) As Integer
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(32) As Integer
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type

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

Function GetTimeZone() As String
Dim tzInfo As TIME_ZONE_INFORMATION
Dim s As String
GetTimeZoneInformation tzInfo
s = IIf(tzInfo.Bias < 0, "+", "-")
GetTimeZone = s & Format((Abs(tzInfo.Bias) \ 60) & ":" & (Abs(tzInfo.Bias) Mod 60), "hh:mm")
End Function

Private Sub Command1_Click()
MsgBox GetTimeZone
End Sub