• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Parsing XML datetime in Android

 
Markus Källander
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

How do I parse an XML datetime in Android? This is the format I want to parse: "2010-05-02T12:05:55+02:00"

Thanks
Markus
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Android supports the java.text.SimpleDateFormat class; that should be sufficient.
 
Markus Källander
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Android supports the java.text.SimpleDateFormat class; that should be sufficient.


I have tried this:


But I get this exception message: java.text.ParseException: Unparseable date: 2010-05-03T10:32:10+02:00
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The " 'Z' " expects a literal "Z"; if you want to parse a timezone then you need to remove the apostrophes.

I don't think "+02:00" is a valid timezone designation, though; something like "GMT+02:00" would be.
 
Tim Holloway
Saloon Keeper
Posts: 18359
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not an "XML" datetime. If there's any chronological data types in XML itself, I'm not aware of it. Schemas don't count.

That form of date looks like ISO-850 (I think it's 850). It should be possible to convert using the SimpleDateFormat converter. I just discovered a "damaged" variant of ISO805 that had to have a minor bit of tweaking before SimpleDateFormat could handle it (from a well-known vendor who should have known better), but if it's truly ISO conformant, the formatter can handle the date/time unassisted.
 
Markus Källander
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:The " 'Z' " expects a literal "Z"; if you want to parse a timezone then you need to remove the apostrophes.

I don't think "+02:00" is a valid timezone designation, though; something like "GMT+02:00" would be.


thanks, it worked fine when I removed the quotes
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic