<分区>
我需要计算两个日期之间的月份, 如果 startDate=2013.01.01, endDate=2013.01.31 答案应该是 1, startDate=2013.01.01, endDate=2013.02.01 答案应该是 2。 请帮忙
标签 java
<分区>
我需要计算两个日期之间的月份, 如果 startDate=2013.01.01, endDate=2013.01.31 答案应该是 1, startDate=2013.01.01, endDate=2013.02.01 答案应该是 2。 请帮忙
最佳答案
使用 Joda Months :
DateTime start = new DateTime(startDate.getTime());
DateTime end= new DateTime(endDate.getTime());
int months = Months.monthBetween(start, end).getMonths();
关于java - 在java中计算两个日期之间的月份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18440083/