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小时)的情况下尝试,或添加一些上午/下午信息