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

intgetBetweenMonths(Date date1, Date date2)
get Between Months
int iMonth = 0;
int flag = 0;
Calendar objCalendarDate1 = Calendar.getInstance();
objCalendarDate1.setTime(date1);
Calendar objCalendarDate2 = Calendar.getInstance();
objCalendarDate2.setTime(date2);
if (objCalendarDate2.equals(objCalendarDate1))
    return 0;
...
longgetBetweenTime(Date begin, Date end, int field)
get Between Time
long between = (end.getTime() - begin.getTime());
switch (field) {
case Calendar.DATE:
    return between / (24 * 60 * 60 * 1000);
case Calendar.HOUR:
    return between / (60 * 60 * 1000);
case Calendar.MINUTE:
    return between / (60 * 1000);
...
DategetBetweenWorkDate(int amount, Date beginDate)
get Between Work Date
int addDate = 0;
for (int ii = 1; ii <= amount; ii++) {
    Calendar cal2 = Calendar.getInstance();
    cal2.setTime(beginDate);
    cal2.add(Calendar.DATE, ii);
    int week = cal2.get(Calendar.DAY_OF_WEEK);
    if (week != 1 && week != 7) {
        addDate++;
...
booleanisBetween(Date check, Date from, Date to)
Used to check if a date is within a given range
if (bypassTodayCheck)
    return true;
if (null == check || null == from || null == to)
    return false;
Calendar start = new GregorianCalendar();
start.setTime(from);
start.set(Calendar.HOUR, 0);
start.set(Calendar.MINUTE, 0);
...
booleanisBetween(Date date, Date d1, Date d2)
Check if date is between d1 and d2
long time = date.getTime();
long time1;
if (d1 != null) {
    time1 = d1.getTime();
} else {
    time1 = Long.MIN_VALUE;
long time2;
...