I'm trying to make a method in java to check if a date is valid Format MM/dd/yyyy
public static boolean checkDate(String date)
{
Calendar cal = Calendar.getInstance();
int year=0,month=0,day=0;
int year2;
year=Integer.parseInt(date.substring(6));
day=Integer.parseInt(date.substring(3,5));
month=Integer.parseInt(date.substring(0,2));
year2=cal.get(Calendar.YEAR);
if(date.length() != 10)
return false;
if(year==year2||year<=year2-100)
return true;
else if(month>12||month<1)
return true;
else if(day<1)
return true;
else if(month==2&&day>28)
return true;
else if((month==1||month==3||month==5||month==7||month==8||month==10||month==12)&&day>31)
return true;
else if((month!=1||month!=3||month!=5||month!=7||month!=8||month!=10||month!=12)&&day>31)
return true;
else
return false;
}
For some reason its not working and I have no idea why. If anyone can see if I made a simple mistake please let me know.