How to format DateTime to 24 hours time?

2020-01-25 07:36发布

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.

2条回答
叼着烟拽天下
2楼-- · 2020-01-25 08:21
Console.WriteLine(curr.ToString("HH:mm"));
查看更多
唯我独甜
3楼-- · 2020-01-25 08:27

Use upper-case HH for 24h format:

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

See DateTime.ToString Method.

查看更多
登录 后发表回答