3

Possible Duplicate:
How to create a .NET DateTime from ISO 8601 format

How can I parse a date string in ISO 8601 format into a datetime object using C#?

2
  • 1
    Is the source string in ISO8601 format or do you want to convert a string to that format? Commented Feb 24, 2011 at 15:39
  • the source string is in ISO8601 format and I want to convert this string to that format into a datetime object. I have his :DateTime.ParseExact("2011-02-14T13:10:30", "yyyy-MM-dd'T'HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); and the result is 2011-02-14 13:10:30 and I am supposed to get 2011-02-14T13:10:30 or Am I wrong to expect this result? Commented Feb 24, 2011 at 17:59

1 Answer 1

5

Use one of the ISO 8601 standard date and time format strings - "O", "o" , "S" and "s" when parsing the string (aka the Roundtrip format specifier) .

The pattern for this specifier reflects a defined standard (ISO 8601). Therefore, it is always the same regardless of the culture used or the format provider supplied.

DateTime dt = DateTime.ParseExact(iso8601String, "s", CultureInfo.InvariantCulture);
Sign up to request clarification or add additional context in comments.

1 Comment

That bombs when the input string contains the "Z" timezone specifier.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.