• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A SimpleDateFormat for ISO 8601

 
Jay Yan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
bart zagers
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for referring Joda! am going through it right now..i hope it solves my problem as well
 
bart zagers
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all replies!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic