public static Date autoParseDateFormat ( String dateString ) { // STEP 1: try to detect standard locale based java date format for ( Locale locale : DateFormat . getAvailableLocales ( ) ) { for ( int style = DateFormat . FULL ; style <= DateFormat . SHORT ; style ++ ) { DateFormat df = DateFormat . getDateInstance ( style , locale ) ; try { return df . parse ( dateString ) ; // either return "true", or return the Date obtained Date // object } catch ( ParseException ex ) { continue ; // unparsable, try the next one } } } // STEP 2: if the date format was not found, check with predefined dates String format = determineDateFormat ( dateString ) ; if ( format != null ) { DateFormat df = new SimpleDateFormat ( format ) ; try { return df . parse ( dateString ) ; } catch ( ParseException e ) { return null ; } } return null ; }
Try to auto - parse the date format