【问题标题】:How can i separate Time and Date in two labels? my code shows both time and date in 1 label如何在两个标签中分隔时间和日期?我的代码在 1 个标签中显示时间和日期
【发布时间】:2019-05-16 19:40:46
【问题描述】:
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) 转到结束清理 错误陷阱: MsgBox "错误:" & Err.Description, vbOKCancel, "获取 UTC 时间时出错"

 EndCleanup:
 Set oWshshell = Nothing
 End Function[enter image description here] 
 [1]

【问题讨论】:

  • Now 将显示日期和时间。 Date 将仅显示日期,Time 将仅显示时间。 Here's VB6 语言参考链接,以防您找不到。

标签: vb6 utc


【解决方案1】:
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")

这解决了它。哈哈

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    • 2019-04-24
    • 2021-07-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多