DateTime.ParseExact returns FormatExpcetion

I have a strange problem:

string format = @"ddd MMM dd hh:mm:ss \G\M\Tzzz yyyy"; __timestamp = "Fri Apr 09 17:02:00 GMT-0500 2010"; DateTime.ParseExact(__timestamp, format, new CultureInfo("en")); 

return FormatException = "The string was not declared a valid DateTime."

but this code goes without exception:

 string format = @"ddd MMM dd hh:mm:ss \G\M\Tzzz yyyy"; __timestamp = "Sat Apr 10 01:27:00 GMT-0500 2010"; DateTime.ParseExact(__timestamp, format, new CultureInfo("en")); 

From 30 thousand parsing dates of this format about 50% unsuccessful with this exception ...

Does anyone know why?

+4
source share
2 answers

it should be HH not HH . You are in a 24-hour format.

 ddd MMM dd HH:mm:ss \G\M\Tzzz yyyy 

Valid: Sat Apr 10 01:27:00 GMT-0500 2010

+10
source

DateTime seems to be expecting AM / PM information for this "en" format provider. Try it with any watch less than 12 (inclusive) or add some AM / PM data

+2
source

All Articles