-1

How to reflect a specific UTC in a VB 6.0 Label in a form. this program will be used by multiple computer with different desktop time so i want 1 UTC to be reflected on that Label.

you see, i'm creating a employee monitoring system for our office, this will be accessed by different computers of different employees in our office that has different desktop time depending on their client but i want my program to show Philippine time only when they're logging in to the monitoring system.

jmcilhinney
  • 50,448
  • 5
  • 26
  • 46
  • If this is a VB6 project then why have you tagged the question as VB.NET but not VB6? Also, do you want UTC or Philippines time? UTC is a specific time zone. It's not a general term for any time zone. – jmcilhinney Nov 15 '18 at 03:56
  • sorry im a newbie on this site, yes i'm actually trying to show the philippine time in a label inside a vb 6.0 form. Can you please help me? Thank you very much! – Jannelyn Morales Nov 16 '18 at 12:11
  • Possible duplicate of [Convert UTC time to local](https://stackoverflow.com/q/23903872/11683) – GSerg Nov 16 '18 at 12:21
  • Actually its different as i want a specific country time to be followed on my vb project regardless of what time or date is displayed on my desktop – Jannelyn Morales Nov 16 '18 at 15:15

1 Answers1

1

You could do something like this:

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]
Eric Moon
  • 101
  • 3
  • thank you :) i'll try if this at home and will update you if this has solved my problem. – Jannelyn Morales Nov 29 '18 at 02:01
  • Dim WithEvents kell As Timer Private Sub kell_Timer() Label1.Caption = Format$(Time, "hh:mm AM/PM") Label2.Caption = Format$(Now, " mmmm dd, yyyy") Label5.Caption = Format$(Now, "mm_dd_yyyy") Label6.Caption = Format$(Time, "hh_mm_AM/PM") End Sub Private Sub Form_Load() Set kell = Form3.Controls.Add("vb.timer", "kell", Form3) With kell: .Interval = 200: .Enabled = True: End With End Sub – Jannelyn Morales Dec 09 '18 at 01:47
  • Eric Moon, the code above will get me the current time set for my pc, can you please teach me how to apply the code you have given me? sorry, i just dont know how to merge that code with my project – Jannelyn Morales Dec 09 '18 at 01:50