开发者

String was not recognized as a valid DateTime ParseExact

开发者 https://www.devze.com 2022-12-19 12:11 出处:网络
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)

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)

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."


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
0

精彩评论

暂无评论...
验证码 换一张
取 消