Possible Duplicate:
Converting ISO8601-compliant String to java.util.Date
I'm trying to convert this String:
2011-06-07T14:08:59.697-07:00
To a Java Date, so far, here's what I did:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S");
Date date1 = sdf.parse("2011-06-07T14:08:59.697", new java.text.ParsePosition(0));
Almost everything is good, except the most important part, the timezone !!
The problem with SimpleDateFormat is that it expect a TimeZone in +/-hhmm
and mine is in +/-hh:mm
format.
Also, and I don't know why, this works:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S Z");
Date date1 = sdf.parse("2011-06-07T14:08:59.697 -0700", new java.text.ParsePosition(0));
But this does not (the space before the timezone):
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SZ");
Date date1 = sdf.parse("2011-06-07T14:08:59.697-0700", new java.text.ParsePosition(0));
What is the correct format to transform this date 2011-06-07T14:08:59.697-07:00
to a java date ?
Thanks for your help!