java日期相减
ublic class Demo5 {
public static void main(String[] args) {
String beginDateStr = "2022-11-01";
String endDateStr = "2022-10-1";
getDaySub(beginDateStr, endDateStr);
}
public static long getDaySub(String beginDateStr, String endDateStr) {
long day = 0;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date beginDate;
Date endDate;
try {
beginDate = format.parse(beginDateStr);
endDate = format.parse(endDateStr);
day = (endDate.getTime() - beginDate.getTime()) / (24 * 60 * 60 * 1000);
} catch (ParseException e) {
e.printStackTrace();
}
System.out.println("day:" + day);
return day;
}
}