public static Date parseDate(String strdate) {

        /* Return in case the string date is not set */
        if (strdate == null || strdate.length() == 0) return null;

        Date result = null;
        strdate = strdate.trim();
        if (strdate.length() > 10) {

            /* Open: deal with +4:00 (no zero before hour) */
            if ((strdate.substring(strdate.length() - 5).indexOf("+") == 0 || strdate.substring(strdate.length() - 5).indexOf("-") == 0) && strdate.substring(strdate.length() - 5).indexOf(":") == 2) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                String sign = strdate.substring(strdate.length() - 5, strdate.length() - 4);
                strdate = strdate.substring(0, strdate.length() - 5) + sign + "0" + strdate.substring(strdate.length() - 4); //$NON-NLS-1$
            }

            String dateEnd = strdate.substring(strdate.length() - 6);

            /*
             * try to deal with -05:00 or +02:00 at end of date replace with -0500 or
             * +0200
             */
            if ((dateEnd.indexOf("-") == 0 || dateEnd.indexOf("+") == 0) && dateEnd.indexOf(":") == 3) { //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
                if (!"GMT".equals(strdate.substring(strdate.length() - 9, strdate.length() - 6))) { //$NON-NLS-1$
                    String oldDate = strdate;
                    String newEnd = dateEnd.substring(0, 3) + dateEnd.substring(4);
                    strdate = oldDate.substring(0, oldDate.length() - 6) + newEnd;
                }
            }
        }

        /* Try to parse the date */
        int i = 0;
        while (i < CUSTOM_DATE_FORMATS.length) {
            try {

                /*
                 * This Block needs to be synchronized, because the parse-Method in
                 * SimpleDateFormat is not Thread-Safe.
                 */
                synchronized (CUSTOM_DATE_FORMATS[i]) {
                    return CUSTOM_DATE_FORMATS[i].parse(strdate);
                }
            } catch (ParseException e) {
                i++;
            } catch (NumberFormatException e) {
                i++;
            }
        }
        return result;
    }
public static Date parseDate ( String strdate ) { if ( strdate == null || strdate . length ( ) == 0 ) return null ; Date result = null ; strdate = strdate . trim ( ) ; if ( strdate . length ( ) > 10 ) { if ( ( strdate . substring ( strdate . length ( ) - 5 ) . indexOf ( "+" ) == 0 || strdate . substring ( strdate . length ( ) - 5 ) . indexOf ( "-" ) == 0 ) && strdate . substring ( strdate . length ( ) - 5 ) . indexOf ( ":" ) == 2 ) { String sign = strdate . substring ( strdate . length ( ) - 5 , strdate . length ( ) - 4 ) ; strdate = strdate . substring ( 0 , strdate . length ( ) - 5 ) + sign + "0" + strdate . substring ( strdate . length ( ) - 4 ) ; } String dateEnd = strdate . substring ( strdate . length ( ) - 6 ) ; if ( ( dateEnd . indexOf ( "-" ) == 0 || dateEnd . indexOf ( "+" ) == 0 ) && dateEnd . indexOf ( ":" ) == 3 ) { if ( ! "GMT" . equals ( strdate . substring ( strdate . length ( ) - 9 , strdate . length ( ) - 6 ) ) ) { String oldDate = strdate ; String newEnd = dateEnd . substring ( 0 , 3 ) + dateEnd . substring ( 4 ) ; strdate = oldDate . substring ( 0 , oldDate . length ( ) - 6 ) + newEnd ; } } } int i = 0 ; while ( i < CUSTOM_DATE_FORMATS . length ) { try { synchronized ( CUSTOM_DATE_FORMATS [ i ] ) { return CUSTOM_DATE_FORMATS [ i ] . parse ( strdate ) ; } } catch ( ParseException e ) { i ++ ; } catch ( NumberFormatException e ) { i ++ ; } } return result ; }
Tries different date formats to parse against the given string
representation to retrieve a valid Date object.

@param strdate Date as String
@return Date The parsed Date