Is there anyway to validate if a given date(yyyy-MM-dd) is a valid date? It should handle leap year too. eg(2015-02-29) should be invalid. I\'m retrieving the date as a stri
This should work for you, I think (if you want to keep it simple).
You have to do setLenient(false) on a SimpleDateFormat.
public static boolean validateDate(String dateString){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
sdf.setLenient(false);
try {
sdf.parse(dateString);
return true;
} catch (ParseException ex) {
return false;
}
}