If I have to accomodate leap years, what will be the best solution?
We are actually having issues fetching age from source system because sometimes it is blank or incorrect.
Hi amathi satya
If you are Java 8, there is a class called Period to deal with date based amount of time. This makes it easier.
You can try below code: (if you are using java 8)
import java.time.format.DateTimeFormatter;import java.time.LocalDate;import java.time.Period;
DateTimeFormatter dateformat = DateTimeFormatter.ofPattern("ddMMyyyy"); //input date format LocalDate date = LocalDate.parse("29121988",dateformat); //input date, change this to give your input date Period p = Period.between(date, today);
days = p.getDays(); months = p.getMonths(); years = p.getYears();
Retrieving data ...