DateTime Format yyyy-mm-dd 24hr

为君一笑 提交于 2019-12-13 10:10:03

问题


How to format a DateTime as follows?

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

example

2001-03-16 14:45:00


回答1:


yyyy-MM-dd HH:mm:ss

For example:

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




回答2:


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.



来源:https://stackoverflow.com/questions/23819538/datetime-format-yyyy-mm-dd-24hr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!