Carlo Adap
Carlo Adap

Reputation: 35

DateTime Format get only the hours

How can i get the Time only in the DateTime?

Example

01/27/12 04:00PM

i want only to display 04:00PM is there a way to get that? :)

Thanks in advance

Upvotes: 0

Views: 1770

Answers (3)

Krunal Mevada
Krunal Mevada

Reputation: 1655

Try This Code :

DateTime thisDate1 = new DateTime(01/27/12 04:00PM);
Console.WriteLine("The current date and time: {0:H:mm:ss zzz}", 
                   thisDate1); 

For more help please visit this link Custom date formate

Upvotes: 0

FLCL
FLCL

Reputation: 2514

Use ToString method with options:

DateTime.Now.ToString("hh:mmtt") 

Upvotes: 0

Jon Skeet
Jon Skeet

Reputation: 1500165

Sure - just specify a custom format string which only includes the information you want. For example, "hh:mmtt" would do what you want here, I believe.

Upvotes: 4

Related Questions