Parsing XML datetime in Android


Last Updated:

  1. marka971

    marka971 Member This Topic's Starter

    Joined:
    Nov 15, 2009
    Messages:
    11
    Likes Received:
    0
    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. disco6stu9

    disco6stu9 Member

    Joined:
    Apr 25, 2010
    Messages:
    10
    Likes Received:
    7
    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 This Topic's Starter

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

    /Markus
     

Share This Page

Loading...