1. Check out our companion app, Forums for Android! Download from Google Play

Parsing XML datetime in Android

Discussion in 'Application Development' started by marka971, May 3, 2010.

  1. marka971

    marka971 Member
    Thread Starter
    15

    Nov 15, 2009
    11
    0
    15
    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
     

    Advertisement

  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
     
  3. marka971

    marka971 Member
    Thread Starter
    15

    Nov 15, 2009
    11
    0
    15
    Thanks, but I managed to solve it yesterday, I had used the wrong formatting string. Embarrassing.... :)

    /Markus
     

Share This Page

Loading...