2012-07-26 37 views
4

我有一個奇怪的問題:DateTime.ParseExact返回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%左右,除此之外失敗...

任何人都知道爲什麼嗎?

回答

10

它應該是HH而不是hh。您使用的是24小時制格式。

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

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

+0

'ddd' not'dddd' – Guvante 2012-07-26 16:56:40

+0

@Guvante thanks :) – 2012-07-26 16:58:50

2

似乎日期時間預計爲 「EN」 格式提供AM/PM信息。嘗試使用小於12(含)的小時,或添加一些AM/PM信息