private static final DateTimeFormatter ymdfmt = DateTimeFormat.forPattern("yyyy-MM-dd");
public static int getIntervalDays(Date fromDate, Date toDate){
try{
return (int)((toDate.getTime() - fromDate.getTime())/(86400*1000));
}catch(Exception e){
e.printStackTrace();
}
return 0;
}
public static int getIntervalDays(String fromDate, String toDate){
try{
return (int) ((ymdfmt.parseMillis(toDate) - ymdfmt.parseMillis(fromDate))/(86400*1000));
}catch(Exception e){
e.printStackTrace();
}
//默认0天
return 0;
}
java 判断两个Date相差的天数
于 2023-01-19 10:34:57 首次发布