convert string to datetime with form yyyy-MM-dd HH:mm:ss in C#
c#, datetime
Solution
I think your parsing worked. The problem is when converting back to string. You can provide the desired format in parameter :
DateTime date = DateTime.ParseExact("2010-01-01 23:00:00", "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
string formattedDate = date.ToString("yyyy-MM-dd HH:mm:ss")
Console.WriteLine(formattedDate);
By default (without a specified format), it uses formatting information derived from the current culture.
Problem
How can I convert this `2014-01-01 23:00:00` to `DateTime` I have done like this: ``` Console.WriteLine(DateTime.ParseExact("2014-01-01 23:00:00", "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)); ``` and the result was like this : ``` 1/1/2014 11:00:00 PM ``` this thing drive me crazy because this format was working in java.