Private Sub Timer1_Timer()
Dim datUTC As Date
datUTC = Time_LocalToUTC(Now)
Me.lblCurrentTimeActual.Caption = Now
Me.lblUTCTimeActual.Caption = CStr(datUTC)
Me.lblPhilippinesTimeActual.Caption =
CStr(DateAdd("h", 8, datUTC))
End Sub
Public Function Time_LocalToUTC(ByVal
the_date As Date) As Date
On Error GoTo ErrorTrap
' Create a new instance of the WScript
Shell
Dim oWshshell As Variant
Dim UTCOffset As Long
Set oWshshell =
CreateObject("WScript.Shell")
'复制世界时的时钟偏移量 注册表,这确实考虑了日光 储蓄
UTCOffset = oWshshell.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias")
'采用当前系统时间,并添加来自注册表的UTC偏移量。 1440年生产 '取60 * 24,因为一天的单位等于1 Time_LocalToUTC = the_date +(UTCOffset / 1440) 转到EndCleanup 错误陷阱: MsgBox“错误:”&错误说明, vbOKCancel,“获取UTC时间出错”
EndCleanup:
Set oWshshell = Nothing
End Function[enter image description here]
[1]
答案 0 :(得分:0)
Me.Label1.Caption = Format$(CStr(DateAdd("h", 8,
datUTC)), "hh:mm:ss AM/PM")
Me.Label2.Caption = Format$(CStr(DateAdd("h", 8,
datUTC)), " mmmm dd, yyyy")
这解决了它。大声笑