/** * 计算两个日期之间相差的天数 */ public static int daysBetween(Date sendDate, Date startDate) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); try { sendDate = sdf.parse(sdf.format(sendDate)); startDate = sdf.parse(sdf.format(startDate)); } catch (Exception e) { e.printStackTrace(); } Calendar cal = Calendar.getInstance(); cal.setTime(sendDate); long time1 = cal.getTimeInMillis(); cal.setTime(startDate); long time2 = cal.getTimeInMillis(); long between_days = (time2 - time1) / (1000 * 3600 * 24); return Integer.parseInt(String.valueOf(between_days)); }
java计算两个日期之间相差的天数
最新推荐文章于 2024-09-25 21:42:32 发布