@Test public void parseTestDate() throws Exception { Calendar cal = DateParser.parse("2012-11-29T13:15:18.176+0000"); assertEquals(13, cal.get(Calendar.HOUR_OF_DAY)); cal = DateParser.parse("2012-11-29T13:15:18.176+0200"); assertEquals(11, cal.get(Calendar.HOUR_OF_DAY)); cal = DateParser.parse("0002-11-29T23:00:00.00Z"); assertEquals(2, cal.get(Calendar.YEAR)); assertEquals(Calendar.NOVEMBER, cal.get(Calendar.MONTH)); }
public static Calendar parse(String str) throws ParseException { if (str == null) { return null; } Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC")); cal.clear(); int len = str.length(); if (len == 0) { return cal; } int i = 0; i = readYear(cal, str, i); i = readCharOpt('-', cal, str, i); if (i == -1) { return cal; } i = readMonth(cal, str, i); i = readCharOpt('-', cal, str, i); if (i == -1) { return cal; } i = readDay(cal, str, i); i = readCharOpt('T', cal, str, i); if (i == -1) { return cal; } i = readHours(cal, str, i); i = readCharOpt(':', cal, str, i); if (i == -1) { return cal; } i = readMinutes(cal, str, i); if (isChar(':', str, i)) { i = readSeconds(cal, str, i + 1); if (isChar('.', str, i)) { i = readMilliseconds(cal, str, i + 1); } } if (i > -1) { readTimeZone(cal, str, i); } return cal; }
DateParser { public static Calendar parse(String str) throws ParseException { if (str == null) { return null; } Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC")); cal.clear(); int len = str.length(); if (len == 0) { return cal; } int i = 0; i = readYear(cal, str, i); i = readCharOpt('-', cal, str, i); if (i == -1) { return cal; } i = readMonth(cal, str, i); i = readCharOpt('-', cal, str, i); if (i == -1) { return cal; } i = readDay(cal, str, i); i = readCharOpt('T', cal, str, i); if (i == -1) { return cal; } i = readHours(cal, str, i); i = readCharOpt(':', cal, str, i); if (i == -1) { return cal; } i = readMinutes(cal, str, i); if (isChar(':', str, i)) { i = readSeconds(cal, str, i + 1); if (isChar('.', str, i)) { i = readMilliseconds(cal, str, i + 1); } } if (i > -1) { readTimeZone(cal, str, i); } return cal; } }
DateParser { public static Calendar parse(String str) throws ParseException { if (str == null) { return null; } Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC")); cal.clear(); int len = str.length(); if (len == 0) { return cal; } int i = 0; i = readYear(cal, str, i); i = readCharOpt('-', cal, str, i); if (i == -1) { return cal; } i = readMonth(cal, str, i); i = readCharOpt('-', cal, str, i); if (i == -1) { return cal; } i = readDay(cal, str, i); i = readCharOpt('T', cal, str, i); if (i == -1) { return cal; } i = readHours(cal, str, i); i = readCharOpt(':', cal, str, i); if (i == -1) { return cal; } i = readMinutes(cal, str, i); if (isChar(':', str, i)) { i = readSeconds(cal, str, i + 1); if (isChar('.', str, i)) { i = readMilliseconds(cal, str, i + 1); } } if (i > -1) { readTimeZone(cal, str, i); } return cal; }  }
DateParser { public static Calendar parse(String str) throws ParseException { if (str == null) { return null; } Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC")); cal.clear(); int len = str.length(); if (len == 0) { return cal; } int i = 0; i = readYear(cal, str, i); i = readCharOpt('-', cal, str, i); if (i == -1) { return cal; } i = readMonth(cal, str, i); i = readCharOpt('-', cal, str, i); if (i == -1) { return cal; } i = readDay(cal, str, i); i = readCharOpt('T', cal, str, i); if (i == -1) { return cal; } i = readHours(cal, str, i); i = readCharOpt(':', cal, str, i); if (i == -1) { return cal; } i = readMinutes(cal, str, i); if (isChar(':', str, i)) { i = readSeconds(cal, str, i + 1); if (isChar('.', str, i)) { i = readMilliseconds(cal, str, i + 1); } } if (i > -1) { readTimeZone(cal, str, i); } return cal; }  static Calendar parse(String str); static Date parseW3CDateTime(String str); static String formatW3CDateTime(Date date); static String formatW3CDateTime(Calendar calendar); }
DateParser { public static Calendar parse(String str) throws ParseException { if (str == null) { return null; } Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC")); cal.clear(); int len = str.length(); if (len == 0) { return cal; } int i = 0; i = readYear(cal, str, i); i = readCharOpt('-', cal, str, i); if (i == -1) { return cal; } i = readMonth(cal, str, i); i = readCharOpt('-', cal, str, i); if (i == -1) { return cal; } i = readDay(cal, str, i); i = readCharOpt('T', cal, str, i); if (i == -1) { return cal; } i = readHours(cal, str, i); i = readCharOpt(':', cal, str, i); if (i == -1) { return cal; } i = readMinutes(cal, str, i); if (isChar(':', str, i)) { i = readSeconds(cal, str, i + 1); if (isChar('.', str, i)) { i = readMilliseconds(cal, str, i + 1); } } if (i > -1) { readTimeZone(cal, str, i); } return cal; }  static Calendar parse(String str); static Date parseW3CDateTime(String str); static String formatW3CDateTime(Date date); static String formatW3CDateTime(Calendar calendar); static final String W3C_DATE_FORMAT; }