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.
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.
Use upper-case HH
for 24h format:
String s = curr.ToString("HH:mm");
See DateTime.ToString Method.
Console.WriteLine(curr.ToString("HH:mm"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With