繁体   English   中英

DateTime.ParseExact返回FormatExpcetion

[英]DateTime.ParseExact returning FormatExpcetion

我有一个奇怪的问题:

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 = “字符串未被识别为有效的DateTime。”

但该代码没有例外:

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(包括)的任何小时,或添加一些AM / PM信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM