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

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

王林
Release: 2023-09-08 21:05:02
forward
1434 people have browsed it

如何将 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();
   }
}
Copy after login

Output

20200727080325
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template