Iam using SimpleDateFormat to parse the string and validate the date. But I am not able to validate the year even if I am passing the wrong year.
This is my code:
Date settlementDate = null;
String dd ="02/27/18888";
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
dateFormat.setLenient(false);
try {
settlementDate = dateFormat.parse(dd);
} catch (ParseException ex) {
ex.printStackTrace();
}
System.out.println("Date is -->> " + settlementDate);
When I run this program I am getting the output as: Date is -->> Fri Feb 27 00:00:00 PST 18888
But I want it should through an exception as I am passing a 5 digit year. Please help and suggest.