• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

A SimpleDateFormat for ISO 8601

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to all replies!
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic