I need to confirm user input as a valid date. User can enter dd / mm / yyyy or mm / yyyy (both valid)
to check it out i did
try{
GregorianCalendar cal = new GregorianCalendar();
cal.setLenient(false);
String []userDate = uDate.split("/");
if(userDate.length == 3){
cal.set(Calendar.YEAR, Integer.parseInt(userDate[2]));
cal.set(Calendar.MONTH, Integer.parseInt(userDate[1]));
cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(userDate[0]));
cal.getTime();
}else if(userDate.length == 2){
cal.set(Calendar.YEAR, Integer.parseInt(userDate[1]));
cal.set(Calendar.MONTH, Integer.parseInt(userDate[0]));
cal.getTime();
}else{
}
}catch(Exception e){
}
since the starting month of GregorianCalendar from 0, 30/01/2009 or 12/2009 gives an error.
any suggestion how to solve this problem.
source
share