How to format DateTime to 24 hours time?

后端 未结 2 1346
盖世英雄少女心
盖世英雄少女心 2020-11-27 06:47

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

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

The o

相关标签:
2条回答
  • 2020-11-27 06:47
    Console.WriteLine(curr.ToString("HH:mm"));
    
    0 讨论(0)
  • 2020-11-27 06:48

    Use upper-case HH for 24h format:

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

    See DateTime.ToString Method.

    0 讨论(0)
提交回复
热议问题