That looks like the ISO 8601 standard date and time format as it is used in XML. Unfortunately, Java's SimpleDateFormat
doesn't support that format properly, because it can't deal with the colon in the timezone.
However, the javax.xml
package contains classes that can deal with this format.
String text = "2011-06-07T14:08:59.697-07:00";
XMLGregorianCalendar cal = DatatypeFactory.newInstance().newXMLGregorianCalendar(text);
If you need it as a java.util.Calendar
then you can call toGregorianCalendar()
on it:
Calendar c2 = cal.toGregorianCalendar();
And ofcourse you can get a java.util.Date
out of that:
Date date = c2.getTime();
You could also use the popular Joda Time library which natively supports this format (and has a much better API for dealing with dates and times than Java's standard library).