Java Utililty Methods Date Between

List of utility methods to do Date Between

Description

The list of methods to do Date Between are organized into topic(s).

Method

intbetweenTwoDates(Date date1, Date date2)
between Two Dates
return (int) ((getMillis(date1) - getMillis(date2)) / (24 * 3600 * 1000));
intdaysBetween(Date d1)
days Between
return (int) ((cal.getTime().getTime() - d1.getTime()) / (1000 * 60 * 60 * 24));
longdaysBetween(Date d1, Date d2)
days Between
return ((d2.getTime() - d1.getTime() + (60 * 60 * 1000L)) / (60 * 60 * 1000L * 24));
longdaysBetween(Date date1, Date date2)
days Between
long diff;
if (date2.after(date1)) {
    diff = date2.getTime() - date1.getTime();
} else {
    diff = date1.getTime() - date2.getTime();
return diff / (24 * 60 * 60 * 1000);
longDaysBetween(Date date1, Date date2)
Days Between
if (date2 == null)
    date2 = new Date();
long day = (date2.getTime() - date1.getTime()) / 86400000L;
return day;
intdaysBetween(Date smdate, Date bdate)
days Between
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
smdate = sdf.parse(sdf.format(smdate));
bdate = sdf.parse(sdf.format(bdate));
Calendar cal = Calendar.getInstance();
cal.setTime(smdate);
long time1 = cal.getTimeInMillis();
cal.setTime(bdate);
long time2 = cal.getTimeInMillis();
...
intdaysBetween(Date smdate, Date bdate)
days Between
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
smdate = sdf.parse(sdf.format(smdate));
bdate = sdf.parse(sdf.format(bdate));
Calendar cal = Calendar.getInstance();
cal.setTime(smdate);
long time1 = cal.getTimeInMillis();
cal.setTime(bdate);
long time2 = cal.getTimeInMillis();
...
StringdaysBetween(Date smdate, Date bdate)
days Between
String days = "";
try {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    smdate = sdf.parse(sdf.format(smdate));
    bdate = sdf.parse(sdf.format(bdate));
    Calendar cal = Calendar.getInstance();
    cal.setTime(smdate);
    long time1 = cal.getTimeInMillis();
...
IntegerdaysBetween(Date smdate, Date bdate)
days Between
try {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    smdate = sdf.parse(sdf.format(smdate));
    bdate = sdf.parse(sdf.format(bdate));
    Calendar cal = Calendar.getInstance();
    cal.setTime(smdate);
    long time1 = cal.getTimeInMillis();
    cal.setTime(bdate);
...
longdaysBetween(Date startDate, Date endDate)
days Between
Calendar start = Calendar.getInstance();
start.setTime(startDate);
Calendar end = Calendar.getInstance();
end.setTime(endDate);
return daysBetween(start, end);