| Author |
A SimpleDateFormat for ISO 8601
|
Jay Yan
Greenhorn
Joined: Feb 04, 2004
Posts: 21
|
|
In an XML file, a date is formatted using ISO 8601 convention. For example: 2005-04-01T13:38:09-08:00 The last part, "-08:00", is the timezone. How to parse such a string? If I use SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"), I can only parse 2005-04-01T13:38:09-0800 Any other way besides removing the last colon then use the SimpleDateFormat above? How to construct a SimpleDateFormat or just DateFormat so that it can handle the dateTime string from XML directly?
|
SCJP, SCBCD, SCEA<br />Oracle Certified DBA
|
 |
Chengwei Lee
Ranch Hand
Joined: Apr 02, 2004
Posts: 884
|
|
Hi, I suppose this is what you're hunting for. Do take note that it is not using the XMLGregorianCalendar class. However, I'm pretty sure you could modify the source to use it. HTH. [ May 02, 2005: Message edited by: Chengwei Lee ]
|
SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
|
 |
bart zagers
Ranch Hand
Joined: Feb 05, 2003
Posts: 234
|
|
An alternative is to use the wonderfull Joda library. This is meant as a replacement for the java.util.date/calendar. It supports both forms of the timezone info in its formatting.
|
 |
Neeraj Dheer
Ranch Hand
Joined: Mar 30, 2005
Posts: 225
|
|
|
Thanks for referring Joda! am going through it right now..i hope it solves my problem as well
|
 |
bart zagers
Ranch Hand
Joined: Feb 05, 2003
Posts: 234
|
|
|
Just in case you missed it. Here (Joda DateTimeFormatter) is specified how to parse the format you mentionned (using 'ZZ' as timezone).
|
 |
Jay Yan
Greenhorn
Joined: Feb 04, 2004
Posts: 21
|
|
|
Thanks to all replies!
|
 |
 |
|
|
subject: A SimpleDateFormat for ISO 8601
|
|
|