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

DategetLastWeekDate(Date date)
get Last Week Date
Calendar c = getCalendar();
c.setTime(date);
c.add(Calendar.WEEK_OF_YEAR, -1);
return c.getTime();
DategetLastWeekDay(int weekDay, Date end)
get Last Week Day
if (end == null)
    throw new IllegalArgumentException("The parameter [end date] should not be null!");
GregorianCalendar cal = getCalender(end);
cal.set(Calendar.DAY_OF_WEEK, weekDay);
if (!cal.getTime().before(end)) {
    cal.add(Calendar.DAY_OF_MONTH, -7);
return cal.getTime();
...
DategetMondayFirstOfWeek(Date baseDate)
get Monday First Of Week
int dayofweek = getDayOfWeekForDate(baseDate);
dayofweek = dayofweek == 1 ? dayofweek + 7 : dayofweek;
return getDateAfterDays(baseDate, 2 - dayofweek);
DategetMondayOfThisWeek(Date date)
get Monday Of This Week
Calendar c = Calendar.getInstance();
c.setTime(date);
int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1;
if (day_of_week == 0)
    day_of_week = 7;
c.add(Calendar.DATE, -day_of_week + 1);
return c.getTime();
DategetMondayOfWeek(Date date)
get Monday Of Week
Calendar monday = Calendar.getInstance();
monday.setTime(date);
monday.setFirstDayOfWeek(FIRST_DAY_OF_WEEK);
monday.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
return monday.getTime();
java.util.DategetNext(final java.util.Date date, final int dayofweek)
get Next
final GregorianCalendar gc = new GregorianCalendar();
gc.setTime(date);
final int actualday = gc.get(Calendar.DAY_OF_WEEK);
gc.add(Calendar.DATE, ((dayofweek - actualday + WEEK_DAYS) % WEEK_DAYS));
return gc.getTime();
LocalDateTimegetNextClosestDateTime(DayOfWeek[] daysOfWeek, int hour, int min)
Gets the next or same closest date from the specified days in daysOfWeek Array at specified hour and min .
return getNextClosestDateTime(Arrays.asList(daysOfWeek), hour, min);
LocalDateTimegetNextClosestDateTime(DayOfWeek[] daysOfWeek, int hour, int min)
Gets the next or same closest date from the specified days in daysOfWeek Array at specified hour and min .
return getNextClosestDateTime(Arrays.asList(daysOfWeek), hour, min);
longgetNextDay(long date, int startOfWeek)
Returns the first day after date that has the day of week matching startOfWeek.
return getDay(date, startOfWeek, 1);
DategetNextWeekDay(Date startDate, int day)
get Next Week Day
Calendar strDate = Calendar.getInstance();
strDate.setFirstDayOfWeek(Calendar.MONDAY);
strDate.setTime(startDate);
strDate.add(Calendar.WEEK_OF_YEAR, 1);
strDate.set(Calendar.DAY_OF_WEEK, day);
return strDate.getTime();