by BehindJava
How to find age using date of birth in Java
In this tutorial we are going to learn about finding the age of a person upon entering the date of birth in Java.
import java.time.LocalDate;
import java.time.Period;
public class BehindJava {
public static void main(String[] args) {
LocalDate today = LocalDate.now();
LocalDate dob = LocalDate.of(1996, 5, 01);
Period period = Period.between(dob, today);
// Now access the values as below
System.out.println(
period.getYears() + "Years" + " " + period.getMonths() + "Months" + " " + period.getDays() + "Days");
}
}
Output:
25Years 8Months 29Days