字符串未被识别为有效的DateTime ParseExact [英] String was not recognized as a valid DateTime ParseExact
本文介绍了字符串未被识别为有效的DateTime ParseExact的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图分析在C#中的日期,并有code以下行
I am trying to parse a date in c# and have the following line of code
DateTime.ParseExact(DateSelected, "ddd MMM dd HH:mm:ss zzz yyyy", Culture)
当我调试DateSelected即将作为星期二2010年2月16日12时36分41秒CST但我得到了厚望说:字符串未被识别为有效的DateTime。
when I debug DateSelected is coming in as "Tue Feb 16 12:36:41 CST 2010" but I get an expection saying "String was not recognized as a valid DateTime."
推荐答案
随着<一href="http://stackoverflow.com/questions/241789/parse-datetime-with-timezone-of-form-pst-cest-utc-etc/241885#241885">this previous问题,区缩写无法识别。试试这个:
Following this previous question, zone abbreviations are not recognized. Try this:
DateTime parsed = DateTime.ParseExact(
"Tue Feb 16 12:36:41 CST 2010".Replace("CST", "+02:00"),
"ddd MMM dd HH:mm:ss zzz yyyy",
new CultureInfo("en-GB"));
这环节也可能是有用的:
This links can also be useful:
- Time zone abbreviations
- TZ4Net Library
- Time Zones in the .NET Framework
这篇关于字符串未被识别为有效的DateTime ParseExact的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文