How to convert C# DateTime to “YYYYMMDDHHMMSS” format?

CsharpServer Side ProgrammingProgramming

Convert the dateTime to toString that results in converting the DateTime to “YYYYMMDDHHMMSS” format

There are also other formats that the dateTime can be converted

MM/dd/yyyy 08/22/2020

dddd, dd MMMM yyyy Tuesday, 22 August 2020

dddd, dd MMMM yyyy HH:mm Tuesday, 22 August 2020 06:30

dddd, dd MMMM yyyy hh:mm tt Tuesday, 22 August 2020 06:30 AM

dddd, dd MMMM yyyy H:mm Tuesday, 22 August 2020 6:30

dddd, dd MMMM yyyy h:mm tt Tuesday, 22 August 2020 6:30 AM

dddd, dd MMMM yyyy HH:mm:ss Tuesday, 22 August 2020 06:30:07

MM/dd/yyyy HH:mm 08/22/2020 06:30

MM/dd/yyyy hh:mm tt 08/22/2020 06:30 AM

MM/dd/yyyy H:mm 08/22/2020 6:30

MM/dd/yyyy h:mm tt 08/22/2020 6:30 AM

MM/dd/yyyy HH:mm:ss 08/22/2020 06:30:07

Example

 Live Demo

class Program {
   static void Main() {
      DateTime d = DateTime.Now;
      string dateString = d.ToString("yyyyMMddHHmmss");
      System.Console.WriteLine(dateString);
      Console.ReadLine();
   }
}

Output

20200727080325
raja
Published on 08-Aug-2020 08:48:46
Advertisements