Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SystemTime in 24 hour format

Status
Not open for further replies.

TBOB

Technical User
Jun 22, 2002
65
0
0
US
I'm trying to show UTC and local time in a 12 and 24 hour format. Im using the following code:

Private Sub Timer1_Timer()

GetSystemTime zt

txt12.Text = Right(DateAdd("h", -5, Format(zt.wHour, "00") & ":" & Format(zt.wMinute, "00") & ":" & Format(zt.wSecond, "00")), 11)

txt24.Text = Right(DateAdd("h", -5, Format(zt.wHour, "00") & ":" & Format(zt.wMinute, "00") & ":" & Format(zt.wSecond, "00")), 11)

txtZT.Text = Format(zt.wHour, "00") & ":" & Format(zt.wMinute, "00") & ":" & Format(zt.wSecond, "00")

End Sub

txt12 is my 12 hour format local time an txtZT is my UTC. They both work fine. I can't figure out how to format to make it local time in the 24 hour format. I've played around with a couple of different things but the best I can get is the local time in 24 hour as a time stamp. Any thoughts would be appreciated. The above code is just where I left it to put it in this thread.

Thanks,

Tony
 
[tt]txt24.Text = Format$(DateAdd("h", -5, Format(zt.wHour, "00") & ":" & Format(zt.wMinute, "00") & ":" & Format(zt.wSecond, "00")), "hh:nn:ss")[/tt]

In my opinion, it is not a good idea to get the local time by querying the UTC system time and adding the local time offset (-5hrs) to get the local time.

Instead of this, you should use the GetLocalTime API function which does the same and gives you the correct local time depnding upon your time zone. Or even better, use VB's internal date and time functions which give the local time. You can use the Format and FormatDateTime functions to convert it to any desired format you want.

 
I'll give that a try.

Thanks,

Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top