Well, Marcin's answers are perfectly correct, but I want to indicate the root of your problem.
When you write
string MessageRecieptDate = messageReceiptDate.Replace("T", " ").Remove(messageReceiptDate.Length-4);
Actually, you delete the line too much. After this line, your line will look like this:
2014-02-03 19:0
Try using Remove(messageReceiptDate.Length - 3); instead Remove(messageReceiptDate.Length - 3); . This will make your line 2014-02-03 19:00 exactly the way we want.
Then you should use the yyyy-MM-dd HH:mm format, which exactly corresponds to 2014-02-03 19:00 .
string messageReceiptDate = "2014-02-03T19:00:00"; string MessageRecieptDate = messageReceiptDate.Replace("T", " ").Remove(messageReceiptDate.Length - 3); IFormatProvider culture = new CultureInfo("en-US"); DateTime dt = DateTime.ParseExact(MessageRecieptDate, "yyyy-MM-dd HH:mm", culture); Console.WriteLine(dt);
The output will be:
2/3/2014 7:00:00 PM
Here is the demo .
Soner gΓΆnΓΌl
source share