DateTime Format yyyy-mm-dd 24hr

2019-09-30 06:18发布

How to format a DateTime as follows?

yyyy-mm-dd hh:mm:ss in 24 hr format

example

2001-03-16 14:45:00

2条回答
太酷不给撩
2楼-- · 2019-09-30 06:52

yyyy-MM-dd HH:mm:ss

For example:

DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss")

查看更多
Deceive 欺骗
3楼-- · 2019-09-30 06:57

You can use the HH format to get the hour in 24h, for sample:

string dateFormated = dateTimeObj.ToString("yyyy-MM-dd HH:mm:ss");

also use MM to get the month in 2 chars. You can take a look at MSDN documentation.

查看更多
登录 后发表回答