• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Parsing XML datetime in Android

marka971

Newbie
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"

I get this timestamp in a JSON document, so I am not using an XML parser.

Thanks
Markus
 
Parsing DateTimes can be done through the DateFormat class. Here's a snippet I found online that should help you out in your case:

DateFormat dfm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
Date a = dfm.parse("2007-02-26 20:15:00 +0200");
(From:Date and time in Java)

You'll probably have to adjust your format string to more closely match the format you're parsing, but the methods to use should be similar

Here's a link to the DateFormat documentation:

Java 2 Platform SE v1.4.2
 
Parsing DateTimes can be done through the DateFormat class. Here's a snippet I found online that should help you out in your case:

DateFormat dfm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
Date a = dfm.parse("2007-02-26 20:15:00 +0200");
(From:Date and time in Java)

You'll probably have to adjust your format string to more closely match the format you're parsing, but the methods to use should be similar

Here's a link to the DateFormat documentation:

Java 2 Platform SE v1.4.2

Thanks, but I managed to solve it yesterday, I had used the wrong formatting string. Embarrassing.... :)

/Markus
 
Back
Top Bottom