I want to calculate my age from date chooser and when i press the button my current age will appear..
how can I do that?
I can do this through this code:
Calendar cal = new GregorianCalendar(1999, 1, 1); //I WANT THIS AGE TO BE INPUT FROM DATESHOOSER)
Calendar now = new GregorianCalendar();
int res = now.get(Calendar.YEAR) - cal.get(Calendar.YEAR);
if ((cal.get(Calendar.MONTH) > now.get(Calendar.MONTH))
|| (cal.get(Calendar.MONTH) == now.get(Calendar.MONTH) && cal.get(Calendar.DAY_OF_MONTH) > now
.get(Calendar.DAY_OF_MONTH))) {
res--;
}
System.out.println(res);
jTextField3.setText(Integer.toString(res));
But I want to make an input from date chooser as my age and I can calculate it by pressing a jbutton