如何在两个标签中分开时间和日期?我的代码在1个标签中同时显示了时间和日期

时间:2018-12-15 23:58:27

标签: vb6 utc

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]

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")

这解决了它。大声笑