I need to check the validity of date against a specified format. After googling, I found one:
public static boolean isThisDateValid(String dateToValidate, String dateFromat){
SimpleDateFormat sdf = new SimpleDateFormat(dateFromat);
sdf.setLenient(false);
ParsePosition position = new ParsePosition(0);
Date date = sdf.parse(dateToValidate,position);
return date != null && position.getIndex() == dateFromat.length();
}
but it is not working..When I ran this, it returned true instead of false.Month value specified is invalid i.e. 13
System.out.println(isThisDateValid("20101331","yyyymmdd"));
Did I miss anything?