转换失败 "date" 未被识别为有效的日期时间

Conversion failed with "date" was not recognized as a valid DateTime

我尝试用下面的代码转换日期,

string currDate = @"Fri, 10 Jul 2020 05:48:28 -0500 (CDT)";
DateTime convDate = Convert.ToDateTime(currDate);

Console.WriteLine("COnverted Date :: " + convDate.ToString("yyyy-MM-dd'T'HH:mm:ss.fffK", CultureInfo.InvariantCulture));

但是,失败并显示以下错误消息,

  Unhandled exception. System.FormatException: String 'Fri, 10 Jul 2020 05:48:28 -0500 (CDT)' was not recognized as a valid DateTime.

如果有人对此提供帮助,那就太好了。

谢谢,

您可以将 (CDT) 放在格式字符串中的单引号中,以便在使用 DateTime.ParseExact 方法解析时忽略它

string currDate = @"Fri, 10 Jul 2020 05:48:28 -0500 (CDT)";
DateTime convDate = DateTime.ParseExact(currDate, "ddd, dd MMM yyyy HH:mm:ss K '(CDT)'", CultureInfo.InvariantCulture);

它returns你是本地日期时间,在我最后输出是

Converted Date :: 2020-07-10T13:48:28.000+03:00

要获得 UTC,您可以将 DateTimeStyles.AdjustToUniversal 参数传递给 ParseExact 方法。它给你

Converted Date :: 2020-07-10T10:48:28.000Z