views:

54

answers:

3

I've found how to turn a DateTime into an ISO 8601 format, but nothing on how to do the reverse in C#.

I have '2010-08-20T15:00:00Z' and I want to turn it into a DateTime object.

I could separate the parts of the string myself, but that seems like a lot of work for something that is already an international standard.

A: 

DateTime.ParseExact(...) allows you to tell the parser what each character represents.

Jerod Houghtelling
A: 

Use DateTime.ParseExact, with "s" as the pattern.

Mamta Dalal
+3  A: 
using System.Globalization;

DateTime d;
DateTime.TryParseExact(
    "2010-08-20T15:00:00Z",
    "s",
    CultureInfo.InvariantCulture,
    DateTimeStyles.AssumeUniversal, out d);
abatishchev