DateTime.ToString get specific time format

G

Grant Merwitz

Hi,

I'm trying to enter the time in the following format:
HH:MM:SS AM/PM

e.g. 05:33:21 PM

How can i achieve this from the Date Time object?

DateTime.Now.ToString("?");

I've search MSDN, and they only seem to cater for the 24 hour clock,
not the 12 hour clock

In the meanwhile, i strip the date by using DateTime.Now.Hour.
and then based on if it's greater than 12.

There must be a simpler built in way

TIA
 
R

Rad [Visual C# MVP]

Hi,

I'm trying to enter the time in the following format:
HH:MM:SS AM/PM

e.g. 05:33:21 PM

How can i achieve this from the Date Time object?

DateTime.Now.ToString("?");

I've search MSDN, and they only seem to cater for the 24 hour clock,
not the 12 hour clock

In the meanwhile, i strip the date by using DateTime.Now.Hour.
and then based on if it's greater than 12.

There must be a simpler built in way

TIA

DateTime.Now.ToString("hh:mm tt")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top