Write a Java 8 program to calculate the age of a person in years given their birthday
Categories: Java 9 Java 8(JDK1.8) Java Java Examples
package r4r.co.in;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
public class CalculateAge {
public static void main(String[] args) {
//Write a Java 8 program to calculate the age of a person in years given their birthday.
LocalDate localDate = LocalDate.now();
LocalDate dateOfBirth = LocalDate.of(1982, 07, 21);
System.out.println("Your Age Year " + ChronoUnit.YEARS.between(dateOfBirth, localDate));
}
}
Output
Your Age Year 42