Java Time period in decimal number of years

前端 未结 3 1001
抹茶落季
抹茶落季 2020-12-22 01:32

If I calculate the difference between 2 LocalDate\'s in java.time using:

Period p = Period.between(testDate, today);
3条回答
  •  攒了一身酷
    2020-12-22 01:42

    I would avoid using Period, and instead just calculate the difference in days:

    float years = testDate1.until(today, ChronoUnit.DAYS) / 365.2425f;
    

提交回复
热议问题