字符串转换为日期在.NET中,如果我收到的日期格式是年月日

字符串转换为日期在.NET中,如果我收到的日期格式是年月日

问题描述:

什么是字符串转换为日期在C#中,如果我收到的日期格式是年月日

What is the best way to convert string to date in C# if my incoming date format is in YYYYMMDD

例如: 20001106

使用DateTime.ParseExact()。是这样的:

Use DateTime.ParseExact(). Something like:

   string date = "20100102";
   DateTime datetime = DateTime.ParseExact(date, "yyyyMMdd", CultureInfo.InvariantCulture);