LocalDate today = LocalDate.now();
LocalDate birthday = LocalDate.of(1987, 09, 24);
Period period = Period.between(birthday, today);
//Now access the values as below
System.out.println(period.getDays());
System.out.println(period.getMonths());
System.out.println(period.getYears());
public int calculateAge(
LocalDate birthDate,
LocalDate currentDate) {
// validate inputs ...
return Period.between(birthDate, currentDate).getYears();
}
public class AgeCalculator {
public static int calculateAge(LocalDate birthDate, LocalDate currentDate) {
if ((birthDate != null) && (currentDate != null)) {
return Period.between(birthDate, currentDate).getYears();
} else {
return 0;
}
}
}