如何使用joda时间计算两个日期之间的“完整”月份数,删除不完整的月份?例如,我有 2 个日期LocalDate from = new LocalDate (2018, 9, 10);LocalDate to = new LocalDate (2018, 11, 15);在这些日期之间有一个“完整”月份 - 10 月从 1 到 31。所以我想通过删除“不完整”月份 - 9 月和 11 月来得到数字“1”我需要这样的东西System.out.println(Months.monthsBetween(from, to).getMonths()); // returns 2System.out.println(Months.**completed**MonthsBetween(from, to).getMonths()); // returns 1UPD 1.我可以实现我想要的如下:LocalDate from = new LocalDate (2018, 9, 10);LocalDate to = new LocalDate (2018, 11, 15);if (to.getDayOfMonth() != 1) from = from.plusMonths(1).withDayOfMonth(1);if (to.getDayOfMonth() != 1) to = to.withDayOfMonth(1);System.out.println(Months.monthsBetween(from, to).getMonths());但也许有一种开箱即用的方法?
添加回答
举报
0/150
提交
取消