SyntaxFix
Write A Post
Hire A Developer
Questions
Tags
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.
This question is related to c# datetime format
c#
datetime
format
Use upper-case HH for 24h format:
HH
String s = curr.ToString("HH:mm");
See DateTime.ToString Method.
Console.WriteLine(curr.ToString("HH:mm"));
Source: Stackoverflow.com