0

I have an ISO 8601 type DateTime string that can come in 2 different forms that I need to parse into a normal local TimeDate in .Net. One like this 2017-12-29T14:49:53.857-06:00 and like this 1974-09-07T00:00:00-05:00 mainly where the seconds is a fractional part and not. How is the best way to do this?

I've tried this for this format, but it doesn't work.

var date= DateTime.ParseExact("1974-09-07T00:00:00-05:00", "yyyy-MM-ddThh:mm:ss zzz", CultureInfo.InvariantCulture);

And this for this format, but it doesn't work.

var date= DateTime.ParseExact("2017-12-29T14:49:53.857-06:00", "yyyy-MM-ddThh:mm:ss.sss zzz", CultureInfo.InvariantCulture);
  • 2
    Does this answer your question? [Parsing ISO 8601 with timezone to .NET datetime](https://stackoverflow.com/questions/17857319/parsing-iso-8601-with-timezone-to-net-datetime) There's also [How to do formally correct parsing of ISO8601 date times in .Net?](https://stackoverflow.com/q/31243985/62576) – Ken White Dec 11 '19 at 23:56
  • Yup, it sure does. I just didn't dig deep enough =) Thank you! –  Dec 12 '19 at 00:02

0 Answers0