It is necessary to calculate the difference (in days) between two points in time. Does not work. Help is needed.

package util; import java.time.LocalDate; import java.time.Period; import java.time.temporal.ChronoUnit; public class CountOfLivedDays { public static void main(String[] args) { LocalDate born = LocalDate.of(2000, 9, 29); LocalDate now = LocalDate.now(); Period period = Period.between(born, now); System.out.println(period.get(ChronoUnit.DAYS)) // 22 System.out.println(period.getYears()); // 16 System.out.println(period.getMonths()); // 2 System.out.println(period.getDays()); // 22 } } 

    1 answer 1

    From en.SO or off. docks To determine the difference in days, you must use the ChronoUnit class and in your case there will be something like this:

     LocalDate born = LocalDate.of(2000, 9, 29); LocalDate now = LocalDate.now(); System.out.println(ChronoUnit.DAYS.between(born, now)); 

    Conclusion:

    5927