C# DateTime to “YYYYMMDDHHMMSS” format

后端 未结 18 1566
故里飘歌
故里飘歌 2020-11-22 01:53

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?

18条回答
  •  灰色年华
    2020-11-22 02:41

    You can use a custom format string:

    DateTime d = DateTime.Now;
    string dateString = d.ToString("yyyyMMddHHmmss");
    

    Substitute "hh" for "HH" if you do not want 24-hour clock time.

提交回复
热议问题