String was not recognized as a valid DateTime ParseExact

前端 未结 1 1914
说谎
说谎 2021-01-13 10:29

I am trying to parse a date in c# and have the following line of code

DateTime.ParseExact(DateSelected, \"ffffd MMM dd HH:mm:ss zzz yyyy\", Culture)

相关标签:
1条回答
  • 2021-01-13 11:15

    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"), 
        "ffffd 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 讨论(0)
提交回复
热议问题