I have a java code, that inputs date in a specific format.
static Date parseDate(String userInput){
DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = null;
try {
date = format.parse(userInput);
System.out.println(date);
}catch(ParseException pe){
date=null;
System.out.println("Not a valid date");
}
return date;
}
Now I'm entering 2015-13-11 89:90:90
which is an invalid date. But it returns Thu Jan 14 18:31:30 IST 2016
as the date. Why is this so? How do I make it to return null as the date?