I am trying to parse date-strings to DateTime objects with the following format:
Tue, 30 Oct 2012 09:51:20 +0000
What I have tried so far is many different variants with DateTime.ParseExact().
I have tried:
DateTime.ParseExact("Mon, 29 Oct 2012 12:13:51 +0000",
"ddd, dd MM yyyy hh':'mm':'ss zzz",
CultureInfo.InvariantCulture);
With thousands different formats as second parameter, using null instead of InvarantCulture as third parameter etc etc. I can't get it to work. How should I parse a string like this?
Many thanks.
How about
var s = "Tue, 30 Oct 2012 09:51:20 +0000";
DateTime.ParseExact(s, "ddd, dd MMM yyyy hh:mm:ss zzz", CultureInfo.InvariantCulture)
The month (Oct
) is actually MMM
, not MM
, and the time (09:51:20
) should be hh:mm:ss
instead of hh':'mm':'ss
.
The correct parsing is
DateTime.ParseExact("Mon, 29 Oct 2012 12:13:51 +0000", "ddd, dd MMM yyyy HH:mm:ss K", CultureInfo.InvariantCulture);
Take a look here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With