显示Vb 6.0项目的特定UTC

时间:2018-11-15 03:12:58

标签: vb6

如何以表格形式在VB 6.0标签中反映特定的UTC。该程序将在具有不同桌面时间的多台计算机上使用,因此我希望1个UTC反映在该标签上。

您看到的,我正在为我们的办公室创建一个员工监控系统,我们办公室中不同员工的不同计算机可以访问该系统,具体取决于客户的桌面时间,但是我希望我的程序仅显示菲律宾时间当他们登录到监视系统时。

1 个答案:

答案 0 :(得分:1)

您可以执行以下操作:

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

  ' Copy the Universal Time clock offset from the registry this does account for daylight savings
  UTCOffset = oWshshell.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias")

  'Take the present system time and add in the UTC offset from the registry. The 1440 is produced
  'by taking 60 * 24 since the units for a day have 1 equaling a day
  Time_LocalToUTC = the_date + (UTCOffset / 1440)
GoTo EndCleanup
ErrorTrap:
    MsgBox "Error: " & Err.Description, vbOKCancel, "Error Getting UTC Time"

EndCleanup:
  Set oWshshell = Nothing
End Function[enter image description here][1]
相关问题