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

DatenextWeek(final Date date)

nextWeek

Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DAY_OF_YEAR, 7);
return cal.getTime();
longpreviousWeek(long date)
Returns the week before date.
return addDays(date, -7);
longpreviousWeek(long date)
Returns the week before date.
return addDays(date, -7);
DatestartOfWeek(Date date)
start Of Week
if (date == null) {
    return date;
Calendar c = Calendar.getInstance();
c.setTime(date);
System.out.println("Today:  " + c.getTime());
c.setTime(date);
c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
...
DatetoStartWeek(Date date)
set the date at the first day of the week.o
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.DAY_OF_WEEK, 3);
return cal.getTime();
DatetoWeekDayUS(Date date, int expect)
to Week Day US
int day = getWeekDay(date);
return adjustDate(date, 0, 0, expect - day);
DatetruncDateToIsoWeek(Date d)
truncate the date to week (does not depend on locale, monday is always the first day in a week)
if (d == null) {
    return null;
Calendar c = Calendar.getInstance();
c.setTime(d);
truncCalendarToIsoWeek(c, -1);
return c.getTime();
intweekCount(Date start, Date end)
week Count
final Calendar startCalendar = Calendar.getInstance();
startCalendar.setTime(start);
final Calendar endCalendar = Calendar.getInstance();
endCalendar.setTime(end);
final int startWeekofYear = startCalendar.get(Calendar.WEEK_OF_YEAR);
final int endWeekofYear = endCalendar.get(Calendar.WEEK_OF_YEAR);
int count = endWeekofYear - startWeekofYear + 1;
if (Calendar.SUNDAY != startCalendar.get(Calendar.DAY_OF_WEEK)) {
...
intweekDay(final Date date)
week Day
return fromDateToCalendar(date).get(DAY_OF_WEEK);
intweekDaysBetween(final Date a, final Date b)
Get week days between two dates inclusive.
int ans = 0;
final Calendar start = Calendar.getInstance();
final Calendar end = Calendar.getInstance();
if (compareDates(a, b) < 0) {
    start.setTime(a);
    end.setTime(b);
} else {
    start.setTime(b);
...