K-leb
K-leb

Reputation: 9

VB.NET TimeOfDay without Date

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?

Upvotes: 0

Views: 1741

Answers (2)

senthilkumar2185
senthilkumar2185

Reputation: 2566

  Dim timeval As DateTime
        Dim newtimeval As String

        timeval = Now.AddHours(-1)
        newtimeval = Format(timeval, "hh:mm:ss")
        MsgBox(newtimeval)

Upvotes: 0

Robin Mackenzie
Robin Mackenzie

Reputation: 19319

Try this:

Dim OneHourAgo As DateTime
Dim FormattedTime As String

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

Debug.Print(FormattedTime)

Upvotes: 2

Related Questions