daysBetween


public int daysBetween(String dateStr) throws ParseException {
Date today = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date compareDate = sdf.parse(dateStr);

Calendar cal = Calendar.getInstance();
cal.setTime(compareDate);
long time1 = cal.getTimeInMillis();

cal.setTime(today);
long time2 = cal.getTimeInMillis();
long between_days = (time2 - time1) / (1000 * 3600 * 24);

return Integer.parseInt(String.valueOf(between_days));
}

你可能感兴趣的:(Java)