GetTimeZoneInformation

Aus API-Wiki
Wechseln zu: Navigation, Suche

Gibt in der Struktur TIME_ZONE_INFORMATION die aktuelle Zeitzoneninformation zurück.

Private Declare Function GetTimeZoneInformation Lib "kernel32" ( _

                        lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long

Beispiel

Private Declare Function GetTimeZoneInformation Lib "kernel32" ( _

                        lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long

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(63) As Byte
   StandardDate As SYSTEMTIME
   StandardBias As Long
   DaylightName(63) As Byte
   DaylightDate As SYSTEMTIME
   DaylightBias As Long

End Type

Option Explicit

Private Sub Command1_Click()

   Dim yy As Long
   Dim mm As Long
   Dim dd As Long
   Dim hh As Long
   Dim nn As Long
   Dim ss As Long
   Dim T As String
   Dim D As String
   Dim Sd As Date
   Dim Tdiff1 As Long
   Dim Tdiff2 As Long
   Dim Summertime As Boolean
   Dim Bias As Long
   Dim utcHour As Long
   Dim StartSummer As Date
   Dim StartWinter As Date
   
   Dim tzi As TIME_ZONE_INFORMATION
   Call GetTimeZoneInformation(tzi)
   yy = Year(Now)
   mm = tzi.DaylightDate.wMonth
   dd = tzi.DaylightDate.wDay
   hh = tzi.DaylightDate.wHour
   nn = 0
   ss = 0
   
   T = TimeSerial(hh, nn, ss)
   D = DateSerial(yy, mm, dd)
   StartSummer = CVDate(D & " " & T) ' Anfang der Sommerzeit
   Debug.Print "Start summer time: " & StartSummer  ' Achtung das Datum ist nicht korrekt,
                                                    ' Da Sommerzeit immer am Wochenende das auf
                                                    ' dieses Datum folgt, umgestellt wird.
   
   Tdiff1 = DateDiff("s", StartSummer, Now)
   
   mm = tzi.StandardDate.wMonth
   dd = tzi.StandardDate.wDay
   hh = tzi.StandardDate.wHour
   nn = 0
   ss = 0
   
   T = TimeSerial(hh, nn, ss)
   D = DateSerial(yy, mm, dd)
   StartWinter = CVDate(D & " " & T)   ' Anfang der Winterzeit
   Debug.Print "Start winter time: " & StartWinter
   
   Tdiff2 = DateDiff("s", StartWinter, Now)
   
   If Tdiff1 >= 0 And Tdiff2 < 0 Then
       Summertime = True
   End If
   
   Bias = tzi.Bias
   
   If Summertime = True Then
       Bias = Bias + tzi.DaylightBias
   End If
   Bias = Bias / 60
   utcHour = Hour(Now) + Bias
   Debug.Print "Local Time: " & Now
   Debug.Print "UTC:        " & DateAdd("h", Bias, Now)
   

End Sub

Quelle

Microsoft MSDN (Englisch)