Why doesn't DateTime.ParseExact work for this example outside of the US?

Viewed 438

I have a string:

var stringDate = "8/19/2016 5:00:00 PM"

and I try using:

var dateTime = DateTime.ParseExact(stringDate,"M/d/yyyy h:mm:ss tt", null);

or

var dateTime = DateTime.ParseExact(stringDate, "M/d/yyyy h:mm:ss tt", 
                                   CultureInfo.Invariant);

or

var dateTime = DateTime.ParseExact(stringDate,"M/d/yyyy h:mm:ss tt",
                                   CultureInfo.GetCultureInfo("en-us"));

It works fine if the machine is in the US but and for all 3 options I get the following error when running from a machine in London:

String was not recognized as a valid DateTime

what am I missing here?

1 Answers
Related