How to format DateTime to 24 hours time?

To convert the DateTime value to its equivalent string representation you should use ToString(format) function. To display time in 24 hours format check this example:

var today = DateTime.Now;
Console.WriteLine(today.ToString("HH:mm"));

DateTime 24 Hour Format>

Read the full list of DateTime C# Formats.
Additional ToString() overloads. Read more here.

Leave a Reply

Your email address will not be published.