Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DateTime.ParseExact返回FormatExpection_C#_.net_String_Exception_Datetime - Fatal编程技术网

C# DateTime.ParseExact返回FormatExpection

C# DateTime.ParseExact返回FormatExpection,c#,.net,string,exception,datetime,C#,.net,String,Exception,Datetime,我有一个奇怪的问题: string format = @"ddd MMM dd hh:mm:ss \G\M\Tzzz yyyy"; __timestamp = "Fri Apr 09 17:02:00 GMT-0500 2010"; DateTime.ParseExact(__timestamp, format, new CultureInfo("en")); 返回的FormatException=“字符串未被识别为有效的日期时间。” 但代码没有例外: string format = @"dd

我有一个奇怪的问题:

string format = @"ddd MMM dd hh:mm:ss \G\M\Tzzz yyyy";
__timestamp = "Fri Apr 09 17:02:00 GMT-0500 2010";
DateTime.ParseExact(__timestamp, format, new CultureInfo("en"));
返回的
FormatException
=“字符串未被识别为有效的日期时间。”

但代码没有例外:

string format = @"ddd MMM dd hh:mm:ss \G\M\Tzzz yyyy";
__timestamp = "Sat Apr 10 01:27:00 GMT-0500 2010";
DateTime.ParseExact(__timestamp, format, new CultureInfo("en"));
从该格式的30k数据解析来看,大约50%的数据解析失败,但有一个例外


有人知道为什么吗?

应该是
HH
而不是
HH
。你是24小时制的

ddd MMM dd HH:mm:ss \G\M\Tzzz yyyy

有效:
Sat Apr 10 01:27:00 GMT-0500 2010

似乎DateTime需要该“en”格式提供程序的AM/PM信息。在任何少于12小时(含12小时)的情况下尝试,或添加一些上午/下午信息