List of utility methods to do Day of Week
boolean | isWeekend(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; ... |
boolean | isWeekend(Date dt) Check whether a date is a weekend return isSaturday(dt) || isSunday(dt);
|
boolean | isWeekEnd(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; |
boolean | isWeekend(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; |
boolean | isWeekendDay(final DayOfWeek nDayOfWeek) is Weekend Day return nDayOfWeek == DayOfWeek.SATURDAY || nDayOfWeek == DayOfWeek.SUNDAY;
|
boolean | isWork(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)); |
DayOfWeek | javaCalendarToNewTimeApi(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: ... |
Date | mergeDayIntoDate(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(); |
Calendar | nextDayOfWeek(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; ... |
Date | nextWeek(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();
|