簡體   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