C# DateTime to “YYYYMMDDHHMMSS” format

2018-12-31 05:58发布

I want to convert a C# DateTime to "YYYYMMDDHHMMSS" format. But I don't find a built in method to get this format? Any comments?

标签: c# datetime
14条回答
谁念西风独自凉
2楼-- · 2018-12-31 07:03
DateTime.Now.ToString("yyyyMMddHHmmss"); // case sensitive
查看更多
步步皆殇っ
3楼-- · 2018-12-31 07:03

You've practically written the format yourself.

yourdate.ToString("yyyyMMddHHmmss")

  • MM = two digit month
  • mm = two digit minutes
  • HH = two digit hour, 24 hour clock
  • hh = two digit hour, 12 hour clock

Everything else should be self-explanatory.

查看更多
登录 后发表回答