Coders Packet

Age calculator in Java using Period class

By Khushboo Jagwani

Age calculator estimates the age of a person from the Date of birth using LocalDate objects, period class, and between() method.

This program is used to calculate the age of a person from the date of birth using LocalDate  objects, two dates being first the date of birth and the second contemporary date.

Period class is used in java. time package which gets the difference between two LocalDate objects.

between() method is used which accepts two LocalDate objects and finds out the difference between two dates.

steps to calculate age from Date of birth:

1. Inputting date of birth.

2. using LocalDate object to convert it into local date

3. Writing Contemporary  date.

4 using between() method as follows:

                int years= Period.between(birthDate,today).getYears();


Download Complete Code


No comments yet