Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format DateTime to 24 hours time?

I need string from datetime to display time in 24 hours format.

.. var curr = DateTime.Now; string s = ???; Console.WriteLine(s); .. 

The output result have to be: "16:38" Thank you.

like image 530
Yara Avatar asked Mar 20 '12 10:03

Yara


People also ask

How do I use 24 hour format in datetime?

Two 'H' in HH is for 24-hour format. Description as to why this works would be useful. Such as HH for 24 hour format as hh for 12 hour.


2 Answers

Use upper-case HH for 24h format:

String s = curr.ToString("HH:mm"); 

See DateTime.ToString Method.

like image 76
Flash Avatar answered Sep 20 '22 11:09

Flash


Console.WriteLine(curr.ToString("HH:mm")); 
like image 45
paul Avatar answered Sep 19 '22 11:09

paul