Reputation: 5792
I have "2010-12-20T11:36:28+0000". How do I parse it into DateTime?
Thanks
Upvotes: 8
Views: 6333
Reputation: 499002
You can use ParseExact
or TryParseExact
with a Custom Date and Time Format String.
Tested:
var myDate = DateTime.ParseExact("2010-12-20T11:36:28+0000",
@"yyyy-MM-dd\THH:mm:ssK",
CultureInfo.InvariantCulture);
Having said that, DateTime.Parse
works perfectly well.
Upvotes: 3
Reputation: 38444
DateTime d = DateTime.Parse("2010-12-20T11:36:28+0000");
Works on my machine and parses time zone.
Upvotes: 19
Reputation: 5638
string date = "2010-12-20T11:36:28+0000";
string start = date.Substring(0, date.IndexOf("T"));
string end = date.Substring(date.IndexOf("T") + 1, date.IndexOf("+") - (date.IndexOf("T") + 1));
DateTime dt = Convert.ToDateTime(start +" "+ end);
Upvotes: 0