How to format DateTime up to 24 hours?

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

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

The output should be: "16:38" Thank you.

+55
c # datetime format
Mar 20 '12 at 10:38
source share
2 answers

Use upper case HH for 24 hour format:

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

See the DateTime.ToString Method .

+141
Mar 20 '12 at 10:41
source share
 Console.WriteLine(curr.ToString("HH:mm")); 
+9
Mar 20 '12 at 10:40
source share



All Articles