字符串没有被识别为有效的DateTime ParseExact

时间:2022-06-11 10:41:49

I am trying to parse a date in c# and have the following line of code

我正在尝试解析c#中的一个日期,并获得以下代码行

DateTime.ParseExact(DateSelected, "ddd MMM dd HH:mm:ss zzz yyyy", Culture)

when I debug DateSelected is coming in as "Tue Feb 16 12:36:41 CST 2010" but I get an expection saying "String was not recognized as a valid DateTime."

当我调试时,所选的数据将以“Tue Feb 16 12:36:41 CST 2010”的形式出现,但我得到的期望是“String was not recognition as valid DateTime”。

1 个解决方案

#1


7  

Following this previous question, zone abbreviations are not recognized. Try this:

在前面的问题之后,区域缩写不被识别。试试这个:

DateTime parsed = DateTime.ParseExact(
    "Tue Feb 16 12:36:41 CST 2010".Replace("CST", "+02:00"), 
    "ddd MMM dd HH:mm:ss zzz yyyy",
    new CultureInfo("en-GB"));

This links can also be useful:

这些链接也可以是有用的:

#1


7  

Following this previous question, zone abbreviations are not recognized. Try this:

在前面的问题之后,区域缩写不被识别。试试这个:

DateTime parsed = DateTime.ParseExact(
    "Tue Feb 16 12:36:41 CST 2010".Replace("CST", "+02:00"), 
    "ddd MMM dd HH:mm:ss zzz yyyy",
    new CultureInfo("en-GB"));

This links can also be useful:

这些链接也可以是有用的: