.NET DateTime to String

99封情书 提交于 2021-02-07 14:50:33

问题


Is there a easy way to convert a DateTime object to a string representation like this '2010-03-03 10:38:48'.

I'm not sure what the above format is but it is different from the patterns obtainable via ToLongTimeString() etc.

Is this a case for string builder?


回答1:


Like this:

date.ToString("yyyy-MM-dd hh:mm:ss")

If you want 24 hour time, replace hh with HH.

For more information, see here.



来源:https://stackoverflow.com/questions/2368253/net-datetime-to-string

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