Because 2014-01-01 23:00:00
IS 2014-01-01 11:00:00 PM
.
Better explanation
You are implicitly calling DateTime.ToString()
, which by default uses the General ("G"
) format, which in the en-US
culture is MM/dd/yyyy hh:mm:ss tt
.
If you want to display the time in a different format, you need to specify it:
string s = DateTime.ParseExact("2010-01-01 23:00:00", "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
Console.WriteLine(s.ToString("yyyy-MM-dd HH:mm:ss");
Or since you're using the same format string, just store it:
string format = "yyyy-MM-dd HH:mm:ss";
DateTime dt = DateTime.ParseExact("2010-01-01 23:00:00", format , CultureInfo.InvariantCulture);
Console.WriteLine(s.ToString(format));