我有一个奇怪的问题:
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。”
但是这段代码没有异常(exception):
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
有效时间:2010 年 4 月 10 日星期六 01:27:00 GMT-0500
关于c# - DateTime.ParseExact 返回 FormatException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11674165/