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

booleanisWeekend(Date date)
Check if the date parameter occurs during a weekend.
if (date != null) {
    Calendar calendar = Calendar.getInstance();
    calendar.setFirstDayOfWeek(Calendar.MONDAY);
    calendar.setTime(date);
    int dayOfTheWeek = calendar.get(Calendar.DAY_OF_WEEK);
    return dayOfTheWeek == Calendar.SATURDAY || dayOfTheWeek == Calendar.SUNDAY;
} else {
    return false;
...
booleanisWeekend(Date dt)
Check whether a date is a weekend
return isSaturday(dt) || isSunday(dt);
booleanisWeekEnd(Date in)
is Week End
if (in == null) {
    return false;
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(in);
return cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY
        || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY;
booleanisWeekend(final Date date)
is Weekend
final Calendar calendar = new GregorianCalendar();
calendar.setTime(date);
return calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
        || calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY;
booleanisWeekendDay(final DayOfWeek nDayOfWeek)
is Weekend Day
return nDayOfWeek == DayOfWeek.SATURDAY || nDayOfWeek == DayOfWeek.SUNDAY;
booleanisWork(String weekday, Date date)
is Work
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int week = (calendar.get(Calendar.DAY_OF_WEEK) - 2 + 7) % 7;
return "1".equals(weekday.substring(week, week + 1));
DayOfWeekjavaCalendarToNewTimeApi(int dayOfWeek)
The method is intended to convert Calendar day of week to DayOfWeek .
switch (dayOfWeek) {
case Calendar.MONDAY:
    return DayOfWeek.MONDAY;
case Calendar.TUESDAY:
    return DayOfWeek.TUESDAY;
case Calendar.WEDNESDAY:
    return DayOfWeek.WEDNESDAY;
case Calendar.THURSDAY:
...
DatemergeDayIntoDate(Date baseDate, int dayOfWeek)
Calculate a new date for a certain day of week and hour of day.
final Calendar c = GregorianCalendar.getInstance();
c.setTime(baseDate);
if (dayOfWeek != -1) {
    c.set(Calendar.DAY_OF_WEEK, dayOfWeek);
return c.getTime();
CalendarnextDayOfWeek(Date fromDate, int dow)
next Day Of Week
Calendar instance = Calendar.getInstance();
if (fromDate != null) {
    instance.setTime(fromDate);
if (dow > 0 && dow < 8) {
    int diff = dow - instance.get(Calendar.DAY_OF_WEEK);
    if (!(diff >= 0)) {
        diff += 7;
...
DatenextWeek(Date date)
next Week
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.setFirstDayOfWeek(Calendar.MONDAY);
calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
calendar.add(Calendar.WEEK_OF_YEAR, 1);
return calendar.getTime();