Home >Backend Development >C#.Net Tutorial >How to convert C# DateTime to 'YYYYMMDDHHMMSS' format?

How to convert C# DateTime to 'YYYYMMDDHHMMSS' format?

王林
王林forward
2023-09-08 21:05:021559browse

如何将 C# DateTime 转换为“YYYYMMDDHHMMSS”格式?

Convert the date and time to toString, thereby converting the date and time to the "YYYYMMDDHHMMSS" format

The date and time can also be converted into other formats

MM/dd /yyyy 08/22/2020

dddd,dd MMMM yyyy Tuesday, August 22, 2020

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

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

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

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

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

Month/Day/Year Hour:Minutes 08/22/2020 06:30

Month/Day/Year Hour:Minutes tt 08/22 / 2020 06:30 AM

year/month/dayH:mm2020年8月22日6:30

year/month/day Hour: Minute tt 08/22/2020 6:30 AM

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

Example

Live demonstration

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

Output

20200727080325

The above is the detailed content of How to convert C# DateTime to 'YYYYMMDDHHMMSS' format?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete