I have DatePicker Dialog, When I select date at that time I want to calculate age it\'s working but when I select date of current year at that time it showing the -1 age instead
public int getAge(int year, int month, int day) {
final Calendar birthDay = Calendar.getInstance();
birthDay.set(year, month, day);
final Calendar current = Calendar.getInstance();
if (current.getTimeInMillis() < birthDay.getTimeInMillis())
throw new IllegalArgumentException("age < 0");
int age = current.get(Calendar.YEAR) - birthDay.get(Calendar.YEAR);
if (birthDay.get(Calendar.MONTH) > current.get(Calendar.MONTH) ||
(birthDay.get(Calendar.MONTH) == current.get(Calendar.MONTH) &&
birthDay.get(Calendar.DATE) > current.get(Calendar.DATE)))
age--;
return age;
}