应该是转化为时间戳来计算。
https://apidoc.gitee.com/dromara/hutool/betweenMonth
public long betweenMonth(boolean isReset)
计算两个日期相差月数
在非重置情况下,如果起始日期的天大于结束日期的天,月数要少算 1 (不足 1 个月)
Parameters:
isReset - 是否重置时间为起始时间(重置天时分秒)
Returns:
相差月数
Since:
3.0.8
```java
public DateBetween(Date begin, Date end, boolean isAbs) {
Assert.notNull(begin, "Begin date is null !", new Object[0]);
Assert.notNull(end, "End date is null !", new Object[0]);
if (isAbs && begin.after(end)) {
this.begin = end;
this.end = begin;
} else {
this.begin = begin;
this.end = end;
}
}
public long betweenMonth(boolean isReset) {
Calendar beginCal = DateUtil.calendar(this.begin);
Calendar endCal = DateUtil.calendar(this.end);
int betweenYear = endCal.get(1) - beginCal.get(1);
int betweenMonthOfYear = endCal.get(2) - beginCal.get(2);
int result = betweenYear * 12 + betweenMonthOfYear;
if (!isReset) {
endCal.set(1, beginCal.get(1));
endCal.set(2, beginCal.get(2));
long between = endCal.getTimeInMillis() - beginCal.getTimeInMillis();
if (between < 0L) {
return (long)(result - 1);
}
}
return (long)result;
}
```