public static int daysBetween(Date startDate, Date endDate)
throws java.text.ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
startDate = sdf.parse(sdf.format(startDate));
endDate = sdf.parse(sdf.format(endDate));
Calendar calendar = Calendar.getInstance();
calendar.setTime(startDate);
long time1 = calendar.getTimeInMillis();
calendar.setTime(endDate);
long time2 = calendar.getTimeInMillis();
long betweenDays = (time2 - time1) / (1000 * 3600 * 24);
return Integer.parseInt(String.valueOf(betweenDays));
}
public static int stringDaysBetween(String smdate, String bdate)
throws ParseException, java.text.ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar cal = Calendar.getInstance();
cal.setTime(sdf.parse(smdate));
long time1 = cal.getTimeInMillis();
cal.setTime(sdf.parse(bdate));
long time2 = cal.getTimeInMillis();
long between_days = (time2 - time1) / (1000 * 3600 * 24);
return Integer.parseInt(String.valueOf(between_days));
}
throws java.text.ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
startDate = sdf.parse(sdf.format(startDate));
endDate = sdf.parse(sdf.format(endDate));
Calendar calendar = Calendar.getInstance();
calendar.setTime(startDate);
long time1 = calendar.getTimeInMillis();
calendar.setTime(endDate);
long time2 = calendar.getTimeInMillis();
long betweenDays = (time2 - time1) / (1000 * 3600 * 24);
return Integer.parseInt(String.valueOf(betweenDays));
}
public static int stringDaysBetween(String smdate, String bdate)
throws ParseException, java.text.ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar cal = Calendar.getInstance();
cal.setTime(sdf.parse(smdate));
long time1 = cal.getTimeInMillis();
cal.setTime(sdf.parse(bdate));
long time2 = cal.getTimeInMillis();
long between_days = (time2 - time1) / (1000 * 3600 * 24);
return Integer.parseInt(String.valueOf(between_days));
}