注意:日期所处前半月和后半月时,相差月分不一样
public static void main(String[] args) {
Date dates = null;
try {
dates = new SimpleDateFormat("yyyy-MM-dd").parse("2019-05-16");
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Date dates1 = null;
try {
dates1 = new SimpleDateFormat("yyyy-MM-dd").parse("2019-11-16");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Instant instant = dates.toInstant();
Instant instant1 = dates1.toInstant();
ZoneId zoneId = ZoneId.systemDefault();
LocalDate one = instant.atZone(zoneId).toLocalDate();
LocalDate two = instant1.atZone(zoneId).toLocalDate();
int ss = Period.between(one,two).getMonths();
log.info("-----"+ss);
}