Google Groups unterstützt keine neuen Usenet-Beiträge oder ‑Abos mehr. Bisherige Inhalte sind weiterhin sichtbar.

GMT and Local Time

4 Aufrufe
Direkt zur ersten ungelesenen Nachricht

ObiWan

ungelesen,
29.03.2022, 09:06:0029.03.22
an

In case you'll need to convert datetime to/from GMT, while checking my
old code I found this snippets which may be useful

Option Explicit

'
' GMTdate - GMT<->Local date/time conversion
'

' System time
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

' Current time zone
Private Type TIME_ZONE_INFORMATION
Bias As Long
StandardName As String * 64
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName As String * 64
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type

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

' converts a date/time from/to GMT
Public Function ConvertDate(ByVal dtDATE As Date, _
ByVal bToGMT As Boolean) As Date
Dim TZI As TIME_ZONE_INFORMATION

On Local Error Resume Next
Call GetTimeZoneInformation(TZI)
If bToGMT Then
' local to GMT
ConvertDate = DateAdd("n", CDbl(TZI.Bias), dtDATE)
Else
' GMT to local
ConvertDate = DateAdd("n", (-1# * CDbl(TZI.Bias)), dtDATE)
End If
End Function


0 neue Nachrichten