我需要计算两个日期之间的月份, 如果startDate = 2013.01.01,endDate = 2013.01.31答案应为1, startDate = 2013.01.01,endDate = 2013.02.01答案应为2。 请帮忙
答案 0 :(得分:8)
使用Joda Months:
DateTime start = new DateTime(startDate.getTime());
DateTime end= new DateTime(endDate.getTime());
int months = Months.monthBetween(start, end).getMonths();