public Date parse ( String dateString ) throws ParseException { Date result = null ; ParseException lastException = null ; for ( DateFormat format : inputFormats ) { try { result = ( ( DateFormat ) format . clone ( ) ) . parse ( dateString ) ; // DateFormat is not thread safe. lastException = null ; break ; } catch ( ParseException e ) { // Keep the first exception that occurred. if ( lastException == null ) { lastException = e ; } // And just try the next input format. } } if ( lastException != null ) { throw lastException ; } return result ; }
Attempts to parse the given string into a java . util . Date using the provided input formats .