DateUtils { public static Date parseDate(String dateValue) throws DateParseException { return parseDate(dateValue, null, null); } private  DateUtils(); static Date parseDate(String dateValue); static Date parseDate(final String dateValue, String[] dateFormats); static Date parseDate(
        String dateValue,
        String[] dateFormats,
        Date startDate
    ); static String formatDate(Date date); static String formatDate(Date date, String pattern); static final String PATTERN_RFC1123; static final String PATTERN_RFC1036; static final String PATTERN_ASCTIME; static final TimeZone GMT; }
@Test public void testBasicDateParse() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(DateUtils.GMT); calendar.set(2005, Calendar.OCTOBER, 14, 0, 0, 0); calendar.set(Calendar.MILLISECOND, 0); Date date1 = calendar.getTime(); String[] formats = new String[] { DateUtils.PATTERN_RFC1123 }; Date date2 = DateUtils.parseDate("Fri, 14 Oct 2005 00:00:00 GMT", formats, null); Assert.assertEquals(date1, date2); date2 = DateUtils.parseDate("Fri, 14 Oct 2005 00:00:00 GMT", formats); Assert.assertEquals(date1, date2); date2 = DateUtils.parseDate("Fri, 14 Oct 2005 00:00:00 GMT"); Assert.assertEquals(date1, date2); }
@Test public void testTwoDigitYearDateParse() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(DateUtils.GMT); calendar.set(2005, Calendar.OCTOBER, 14, 0, 0, 0); calendar.set(Calendar.MILLISECOND, 0); Date date1 = calendar.getTime(); String[] formats = new String[] { DateUtils.PATTERN_RFC1036 }; Date date2 = DateUtils.parseDate("Friday, 14-Oct-05 00:00:00 GMT", formats, null); Assert.assertEquals(date1, date2); calendar.set(1900, Calendar.JANUARY, 0, 0, 0, 0); calendar.set(Calendar.MILLISECOND, 0); Date startDate = calendar.getTime(); calendar.set(1905, Calendar.OCTOBER, 14, 0, 0, 0); calendar.set(Calendar.MILLISECOND, 0); date1 = calendar.getTime(); date2 = DateUtils.parseDate("Friday, 14-Oct-05 00:00:00 GMT", formats, startDate); Assert.assertEquals(date1, date2); }
@Test public void testParseQuotedDate() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(DateUtils.GMT); calendar.set(2005, Calendar.OCTOBER, 14, 0, 0, 0); calendar.set(Calendar.MILLISECOND, 0); Date date1 = calendar.getTime(); String[] formats = new String[] { DateUtils.PATTERN_RFC1123 }; Date date2 = DateUtils.parseDate("'Fri, 14 Oct 2005 00:00:00 GMT'", formats); Assert.assertEquals(date1, date2); }