How to calculate the current age from your birthday using java.time.LocalDate.
BirthdayService.java
public int getAge(int year, int month, int day) {
//Birthday to be calculated
LocalDate birthday = LocalDate.of(year, month, day);
//Current date
LocalDate today = LocalDate.now();
long duration = ChronoUnit.YEARS.between(birthday, today);
return (int)duration;
}
LocalDate (Java Platform SE 8)
Recommended Posts