我有不同的日期时间格式。当我尝试解析它时,出现错误'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