//计算两日期相差天数
public int testBetweenDays(Date opDate,Date enDate) {
// 获取相差的天数
Calendar calendar = Calendar.getInstance();
calendar.setTime(opDate);
long timeInMillis1 = calendar.getTimeInMillis();
calendar.setTime(enDate);
long timeInMillis2 = calendar.getTimeInMillis();
int betweenDays = (int) ((timeInMillis2 - timeInMillis1) / (1000L * 3600L * 24L));
return betweenDays;
}
public Date addDayOfDate(Date date,int i){
Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(Calendar.DATE, i);
Date newDate = c.getTime();
return newDate;
}
来源:CSDN
作者:矮小的高个子
链接:https://blog.csdn.net/crazyo2jam/article/details/103708618