Here you can find the source of readDate(XmlPullParser parser, String tagName, String dateFormat)
Parameter | Description |
---|---|
parser | The parser to read the date from |
tagName | the name of the tag that contains the date |
dateFormat | The date format see SimpleDateFormat for formatting options |
Parameter | Description |
---|---|
IOException | an exception |
XmlPullParserException | an exception |
public static Date readDate(XmlPullParser parser, String tagName, String dateFormat) throws IOException, XmlPullParserException
//package com.java2s; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { public static final String NAMESPACE = null; /**//from w ww .j av a2 s . c o m * Reads a date from the next xml tag * * @param parser The parser to read the date from * @param tagName the name of the tag that contains the date * @param dateFormat The date format see {@link SimpleDateFormat} for formatting options * @return {@link Date} or null on parseError * @throws IOException * @throws XmlPullParserException */ public static Date readDate(XmlPullParser parser, String tagName, String dateFormat) throws IOException, XmlPullParserException { parser.require(XmlPullParser.START_TAG, NAMESPACE, tagName); Date date = null; SimpleDateFormat simpleDateFormat = new SimpleDateFormat( dateFormat, Locale.ENGLISH); if (parser.next() == XmlPullParser.TEXT) { try { date = simpleDateFormat.parse(parser.getText()); } catch (ParseException e) { return null; } parser.next(); } parser.require(XmlPullParser.END_TAG, NAMESPACE, tagName); return date; } }