Java Utililty Methods Day of Week

List of utility methods to do Day of Week

Description

The list of methods to do Day of Week are organized into topic(s).

Method

booleanisMatchWeek(Date date, int week)
is Match Week
return getWeekOfDate(date) == week;
booleanisOnWeekend(Date date)
Uses the Calendar to see of the day of week is equal to saturday or sunday.
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return ((cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)
        || (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY));
booleanisSameWeekDates(Date date1, Date date2)
is Same Week Dates
long diff = getMonday(date1).getTime() - getMonday(date2).getTime();
if (Math.abs(diff) < 1000 * 60 * 60 * 24) {
    return true;
} else {
    return false;
booleanisWeekday(Date startDate)
decides if a day is Mon through Fri
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(startDate);
if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)
    return false;
return true;
booleanisWeekDay(final Date date)
Figure out whether a Date is a week day.
if (null == date) {
    return false;
Calendar cal = Calendar.getInstance();
cal.setTime(date);
if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
        || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
    return false;
...
booleanisWeekEnd(Date date)
is Week End
Calendar cal = Calendar.getInstance();
cal.setTime(date);
if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)
    return true;
else
    return false;
booleanisWeekend(Date date)
is Weekend
Calendar c = Calendar.getInstance();
if (date != null)
    c.setTime(date);
int weekDay = c.get(7);
return ((weekDay == 1) || (weekDay == 7));
booleanisWeekend(Date date)
is Weekend
boolean result = false;
int day = getDayOfWeek(date);
result = false;
result = result || day == Calendar.SATURDAY;
result = result || day == Calendar.SUNDAY;
return result;
booleanisWeekend(Date date)
Tests the input date to check if the date falls on a weekend.
if (isSaturday(date) || isSunday(date))
    return true;
else
    return false;
booleanisWeekend(Date date)
is Weekend
return isWeekend(calendar(date));