File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes A SimpleDateFormat for ISO 8601 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "A SimpleDateFormat for ISO 8601" Watch "A SimpleDateFormat for ISO 8601" New topic

A SimpleDateFormat for ISO 8601

Jay Yan

Joined: Feb 04, 2004
Posts: 21
In an XML file, a date is formatted using ISO 8601 convention.
For example:

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

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

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.

[ 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 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

Joined: Feb 04, 2004
Posts: 21
Thanks to all replies!
I agree. Here's the link:
subject: A SimpleDateFormat for ISO 8601
Similar Threads
how to get user defined timezone using XMLGregorianCalendar.
back ground process id ??
String convert in to Date format
Converting from string to date
Handling a strange date format