Parsing ISO 8601 Date Format in Java

      Comments Off on Parsing ISO 8601 Date Format in Java

These are dates in a format like “2010-05-17T09:30:47-04:00” optionally including date, time and time zone, which are commonly found in XML documents.

In .NET you can just use DateTime.Parse(), but in Java the answer is not as obvious.

Assuming that you are using the Apache libraries, the simplest approach is probably to just use org.apache.xmlbeans.XmlCalendar:

Calendar c = new XmlCalendar("2010-05-17T09:30:47-04:00");

If that isn’t an option, try this.