2017-03-01 172 views
0

我有以下格式的字符串:格式化日期時間錯誤

29-Feb-17 03.36.15.1902 PM 

,我試圖把它轉換成一個DateTime對象用下面的代碼:

DateTime.ParseExact(request.DispatchTime, "dd-MMM-yy hh.mm.ss.ffff tt", CultureInfo.InvariantCulture); 

但得到的錯誤:

The DateTime represented by the string is not supported in calendar System.Globalization.GregorianCalendar. 
+0

格式不受GregorianCalendar類支持,因爲錯誤狀態。 '17-Feb-17'是一個不好的格式,因爲假設'17',我們不知道你的意思是'1917'還是'2017',所以'DateTime'通常也不支持。 –

回答

6
29-Feb-17 

是不是現有datetime。因此,相應的庫無法解析它

+2

這不應該是一個評論? – lokusking

+1

@lokusking:如果這是一個有效的問題,這是一個有效的答案。沒有辦法解決它 –

+0

@TimSchmelter有一種方法可以解決這個問題,這是爲了讓OP在他們的字符串中使用適當的日期格式。 –