我有不同的日期時間格式。當我嘗試解析它時,出現錯誤'System.FormatException' 。我怎麼解析它?如何從此格式解析日期時間?
?time
"20170620 21:22:02 EST"
?DateTime.Parse(time)
'DateTime.Parse(time)' threw an exception of type 'System.FormatException'
Data: {System.Collections.ListDictionaryInternal}
HResult: -2146233033
HelpLink: null
InnerException: null
Message: "String was not recognized as a valid DateTime."
Source: "mscorlib"
StackTrace: " at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)\r\n at System.DateTime.Parse(String s)"
TargetSite: {System.DateTime Parse(System.String, System.Globalization.DateTimeFormatInfo, System.Globalization.DateTimeStyles)}
由於偏移量是硬編碼或存在數據庫派生,因此沒有公佈的答案處理夏令時。
[將字符串解析爲C#中的DateTime]可能的重複(https://stackoverflow.com/questions/5366285/parse-string-to-datetime-in-c-sharp) – lebelinoz
[Parse DateTime with time形式爲PST/CEST/UTC/etc]的區域(https://stackoverflow.com/questions/241789/parse-datetime-with-time-zone-of-form-pst-cest-utc-etc) –
其不是重複,因爲該鏈接沒有解決日光節省偏移 – junkone