tags:

views:

361

answers:

1

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

+6  A: 

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:

Rubens Farias
This could be pretty clean, if there was a comprehensive list of timezeones.
John Gietzen
just updated this answer with that list
Rubens Farias
works like a charm now thanks for the help
Deathbat