This repository was archived by the owner on Mar 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUTCDateTime.bas
53 lines (47 loc) · 1.54 KB
/
UTCDateTime.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
Attribute VB_Name = "UTCDateTime"
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(63) As Byte 'unicode (0-based)
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(63) As Byte 'unicode (0-based)
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type
Private Declare Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
Private Sub Form_Load()
txtDate.Text = GetUDTDateTime()
End Sub
Public Function GetUDTDateTime() As String
Const TIME_ZONE_ID_DAYLIGHT As Long = 2
Dim tzi As TIME_ZONE_INFORMATION
Dim dwBias As Long
'Dim sZone As String
Dim tmp As String
Select Case GetTimeZoneInformation(tzi)
Case TIME_ZONE_ID_DAYLIGHT
dwBias = tzi.Bias + tzi.DaylightBias
'sZone = " (" & Left$(tzi.DaylightName, 1) & "DT)"
Case Else
dwBias = tzi.Bias + tzi.StandardBias
'sZone = " (" & Left$(tzi.StandardName, 1) & "ST)"
End Select
tmp = " " & Right$("00" & CStr(dwBias \ 60), 2) & ":" & Right$("00" & CStr(dwBias Mod 60), 2)
If dwBias > 0 Then
Mid$(tmp, 1, 1) = "-"
Else
Mid$(tmp, 1, 2) = "+0"
End If
GetUDTDateTime = Format$(Now, "yyyy-mm-ddTHh:Mm:Ss") & tmp
End Function