Java Utililty Methods Date Before

List of utility methods to do Date Before

Description

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

Method

booleanbefore(Date point, Date when)
Returns true if the given from Date is before the given when Date otherwise false.
final Calendar pointCalendar = Calendar.getInstance();
pointCalendar.setTime(point);
final Calendar whenCalendar = Calendar.getInstance();
whenCalendar.setTime(when);
return pointCalendar.before(whenCalendar);
booleanbefore(Date sDate, Date eDate)
before
Calendar sCal = new GregorianCalendar();
sCal.setTime(sDate);
Calendar eCal = new GregorianCalendar();
eCal.setTime(eDate);
return sCal.before(eCal);
booleanbeforeDay(final Date date1, final Date date2)
Get date one day before specified one.
if (date1 == null)
    return true;
return getStartOfDate(date1).before(getStartOfDate(date2));
booleanbeforeDays(Date date, Integer days)
before Days
if (date == null || days == null)
    return false;
Long time = System.currentTimeMillis() - date.getTime();
return time < (days * 86400000);
booleanbeforeTime(Date time1, Date time2)
before Time
Calendar calendar1 = Calendar.getInstance();
calendar1.setTime(time1);
Calendar calendar2 = Calendar.getInstance();
calendar2.setTime(time2);
return calendar1.before(calendar2);
intdaysBefore(Date date1)
days Before
Calendar cal = Calendar.getInstance();
cal.setTime(date1);
long time1 = cal.getTimeInMillis();
long time2 = System.currentTimeMillis();
long between_days = (time2 - time1) / (1000 * 3600 * 24);
return Integer.parseInt(String.valueOf(between_days));
DategetBefore(Date date)
get Before
return getBefore(date, -1);
CalendargetBeforeDate(final int unit, final int period)
get Before Date
Calendar deleteTimeCalendar = Calendar.getInstance();
deleteTimeCalendar.add(unit, -1 * period);
return deleteTimeCalendar;
DategetBeforeDate(String range)
get Before Date
Calendar today = Calendar.getInstance();
if ("week".equalsIgnoreCase(range))
    today.add(4, -1);
else if ("month".equalsIgnoreCase(range))
    today.add(2, -1);
else
    today.clear();
return today.getTime();
...
DategetBeforeHourByCurrentTime(Date now, int mount)
get Before Hour By Current Time
Calendar c = Calendar.getInstance();
c.setTime(now);
c.set(Calendar.HOUR_OF_DAY, c.get(Calendar.HOUR_OF_DAY) + mount);
return c.getTime();