public static Date parseDate(String dateValue, Collection<String> dateFormats, Date startDate)
    throws ParseException {

        if (dateValue == null) {
            throw new IllegalArgumentException("dateValue is null");
        }
        if (dateFormats == null) {
            dateFormats = DEFAULT_HTTP_CLIENT_PATTERNS;
        }
        if (startDate == null) {
            startDate = DEFAULT_TWO_DIGIT_YEAR_START;
        }
        // trim single quotes around date if present
        // see issue #5279
        if ((dateValue.length() > 1) && dateValue.startsWith("'") && dateValue.endsWith("'")) {
            dateValue = dateValue.substring(1, dateValue.length() - 1);
        }

        SimpleDateFormat dateParser = null;
        Iterator formatIter = dateFormats.iterator();

        while (formatIter.hasNext()) {
            String format = (String)formatIter.next();
            if (dateParser == null) {
                dateParser = new SimpleDateFormat(format, Locale.ENGLISH);
                dateParser.setTimeZone(TIMEZONE_GMT);
                dateParser.set2DigitYearStart(startDate);
            } else {
                dateParser.applyPattern(format);
            }
            try {
                return dateParser.parse(dateValue);
            } catch (ParseException pe) {
                // ignore this exception, we will try the next format
            }
        }

        // we were unable to parse the date
        throw new ParseException("Unable to parse the date " + dateValue, 0);
    }
public static Date parseDate ( String dateValue , Collection < String > dateFormats , Date startDate ) throws ParseException { if ( dateValue == null ) { throw new IllegalArgumentException ( "dateValue is null" ) ; } if ( dateFormats == null ) { dateFormats = DEFAULT_HTTP_CLIENT_PATTERNS ; } if ( startDate == null ) { startDate = DEFAULT_TWO_DIGIT_YEAR_START ; } if ( ( dateValue . length ( ) > 1 ) && dateValue . startsWith ( "'" ) && dateValue . endsWith ( "'" ) ) { dateValue = dateValue . substring ( 1 , dateValue . length ( ) - 1 ) ; } SimpleDateFormat dateParser = null ; Iterator formatIter = dateFormats . iterator ( ) ; while ( formatIter . hasNext ( ) ) { String format = ( String ) formatIter . next ( ) ; if ( dateParser == null ) { dateParser = new SimpleDateFormat ( format , Locale . ENGLISH ) ; dateParser . setTimeZone ( TIMEZONE_GMT ) ; dateParser . set2DigitYearStart ( startDate ) ; } else { dateParser . applyPattern ( format ) ; } try { return dateParser . parse ( dateValue ) ; } catch ( ParseException pe ) { } } throw new ParseException ( "Unable to parse the date " + dateValue , 0 ) ; }
Slightly modified from org.apache.commons.httpclient.util.DateUtil.parseDate
<p>
Parses the date value using the given date formats.

@param dateValue   the date value to parse
@param dateFormats the date formats to use
@param startDate   During parsing, two digit years will be placed in the range
<code>startDate</code> to <code>startDate + 100 years</code>. This value may
be <code>null</code>. When <code>null</code> is given as a parameter, year
<code>2000</code> will be used.
@return the parsed date
@throws ParseException if none of the dataFormats could parse the dateValue