List of utility methods to do Day of Week
Date | nextWeek(final Date date) nextWeek Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DAY_OF_YEAR, 7);
return cal.getTime();
|
long | previousWeek(long date) Returns the week before date .
return addDays(date, -7);
|
long | previousWeek(long date) Returns the week before date .
return addDays(date, -7);
|
Date | startOfWeek(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); ... |
Date | toStartWeek(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();
|
Date | toWeekDayUS(Date date, int expect) to Week Day US int day = getWeekDay(date); return adjustDate(date, 0, 0, expect - day); |
Date | truncDateToIsoWeek(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(); |
int | weekCount(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)) { ... |
int | weekDay(final Date date) week Day return fromDateToCalendar(date).get(DAY_OF_WEEK);
|
int | weekDaysBetween(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); ... |