madmike
madmike

Reputation: 114

Date.Now not displaying 12 hour format

I know this probably is considered a repeat question so I will apologize in advance, but I have looked at question after question and everyone says the "hh" will display a 12 hour format. I keep getting a 24 hour format as if I have "HH". What gives?

strTime = Date.Now.ToString("hhmmsstt")

Upvotes: 2

Views: 208

Answers (4)

codemonkeyliketab
codemonkeyliketab

Reputation: 320

You can try

strTime = Date.Now.ToLocalTime()

to get a local time.

Upvotes: 0

Milton Cardoso
Milton Cardoso

Reputation: 358

You can use it like this

strtime = Format(Now, "hh:mm tt")

You get an output like this

04:33 PM

If for something you dont want the 0 behind 4 you just take out one h

strtime = Format(Now, "h:mm tt")

Upvotes: 0

gyurix
gyurix

Reputation: 1086

https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1

On this link you can check all the possible time formats, so you are interested about the following:

"h"

The hour, using a 12-hour clock from 1 to 12.

More information: The "h" Custom Format Specifier.

"hh"

The hour, using a 12-hour clock from 01 to 12.

More information: The "hh" Custom Format Specifier.

"H"

The hour, using a 24-hour clock from 0 to 23.

More information: The "H" Custom Format Specifier.

"HH"

The hour, using a 24-hour clock from 00 to 23.

More information: The "HH" Custom Format Specifier.

Upvotes: 1

gyurix
gyurix

Reputation: 1086

HH is 24 hour format while hh is 12 hour one

Upvotes: 1

Related Questions