age in java 1

age in java

LocalDate today =;
LocalDate birthday = LocalDate.of(1987, 09, 24);

Period period = Period.between(birthday, today);

//Now access the values as below

Here is what the above code is Doing:
1. We are creating two LocalDate objects, one for today and one for the birthday.
2. We are using the between() method of the Period class to get the difference between the two dates.
3. We are using the getDays(), getMonths() and getYears() methods to get the difference in days, months and years.

Similar Posts