How do I format hours in DateTime to return 0 instead of 12?
.net, c#, datetime, formatting
Solution
Try
string s = dt.ToString("H:mm:ss");
Here's the reference page.
Problem
By default, the hour in a format string for a DateTime transforms 0 into 12. For example, if you have ``` DateTime dt = new DateTime(1999, 1, 1, 0, 0, 0); string s = dt.ToString("h:mm:ss"); ``` the value of s will be "12:0:0", not "0:0:0". Is there a way to get "0:00:00" instead?