LocalDate birthday = LocalDate.of(2000, Month.JANUARY, 1); LocalDate currDay = LocalDate.now(); System.out.println(birthday.until(currDay)); 

I get P16Y9M3D, but I want 16 * 12 + 9 months and 3 days

    1 answer 1

    Instead of using the standard conversion to a string (implicitly calling the toString method), first save the period into a separate variable, get the necessary properties from it and print the line:

     Period period = birthday.until(currDay); System.out.println(period.getYears() * 12 + period.getMonths() + " месяцев и " + period.getDays() + " дня"); 

    The latter can be replaced by:

     System.out.printf("%d месяцев и %d дней", period.getYears() * 12 + period.getMonths(), period.getDays());