You ask for the difference in years, months, and days, so you return for 1 year, 10 months, and 29 days.
Just use:
int months = Months.monthsBetween(date1, date2).getMonths();
Or, if you really want to use the new Period and maybe get the days, you can use:
PeriodType monthDay = PeriodType.yearMonthDayTime().withYearsRemoved(); Period difference = new Period(date1, date2, monthDay);
You can simply use PeriodType.months() , but if you are really only interested in months, I would use the first snippet above to do it all in one short different statement.
source share