Java Time period in decimal number of years

前端 未结 3 1000
抹茶落季
抹茶落季 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:45

    You mentioned in one of your comments that you need quarter year precision if you need the current quarter you can use IsoFields.QUARTER_YEARS:

    double yearAndQuarter = testDate.until(today, IsoFields.QUARTER_YEARS) / 4.0;
    

    This way you will actually use the time api, always get the correct result and @Mike won't have to loathe anything.

提交回复
热议问题