0

I'm trying to show the time of day using the computer's clock, but in the previous time zone (i.e. -1 hour).

I've been doing it this way:

        Dim Tneg1 As String = Now.AddHours(-1)
    lblClock.Text = UTCneg1

Where Tneg1 is a variable to represent the time with 1 hour subtracted.

However, using the Now property shows both the date and the hh:mm:ss. I only want the hh:mm:ss. How do I do this?

K-leb
  • 9
  • 5

2 Answers2

2

Try this:

Dim OneHourAgo As DateTime
Dim FormattedTime As String

OneHourAgo = Now.AddHours(-1)
FormattedTime = OneHourAgo.ToString("HH:mm:ss")

Debug.Print(FormattedTime)
Robin Mackenzie
  • 18,801
  • 7
  • 38
  • 56
0
  Dim timeval As DateTime
        Dim newtimeval As String

        timeval = Now.AddHours(-1)
        newtimeval = Format(timeval, "hh:mm:ss")
        MsgBox(newtimeval)
senthilkumar2185
  • 2,536
  • 3
  • 22
  • 36