参考 :
https://www.jb51.net/article/144313.htm
/**
* 两个日期间相差的天数 这里不包含起始日期,如果想要结果包含起始日期,则需要再结果上+1
* @return
*/
public int getDifferenceDayCount(String startDateStr,String endDateStr){
LocalDate startDate = LocalDate.parse(startDateStr);
LocalDate endDate = LocalDate.parse(endDateStr);
//取正数
return Math.abs((int)(endDate.toEpochDay() - startDate.toEpochDay()));
}
调用
System.out.println(getDifferenceDayCount("2019-07-08","2019-06-29"));//不包含起始日期的天数获取
System.out.println(getDifferenceDayCount("2019-06-29","2019-07-08")+1);//包含起始日期的天数获取