Add SimpleDateFormat#setLenient()
to your convertDateFormat
method:
private String convertDateFormat(String date, String oPattern, String ePattern) throws ParseException {
SimpleDateFormat normalFormat = new SimpleDateFormat(oPattern);
normalFormat.setLenient(false); /* <-- Add this line -- */
Date d = normalFormat.parse(date);
SimpleDateFormat cardFormat = new SimpleDateFormat(ePattern);
return cardFormat.format(d);
}
It will make the convertDateFormat
fail if the date is incorrect.
This is explained in detail here: http://eyalsch.wordpress.com/2009/05/29/sdf/