C# DateTime to “YYYYMMDDHHMMSS” format

后端 未结 18 1558
故里飘歌
故里飘歌 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:45

    I am surprised no one has a link for this . any format can be created using the guidelines here:

    Custom Date and Time Format Strings

    For your specific example (As others have indicated) use something like

    my_format="yyyyMMddHHmmss";
    DateTime.Now.ToString(my_format);
    

    Where my_format can be any string combination of y,M,H,m,s,f,F and more! Check out the link.

提交回复
热议问题