List of utility methods to do Calendar Week
int | convertIntToCalendarDayOfWeek(int dayOfWeek) convert Int To Calendar Day Of Week return dayOfWeek == Calendar.SUNDAY ? 7 : dayOfWeek - 1;
|
Date | endOfWeek(Calendar calendar, Date date) Adjusts the calendar to the end of the current week. calendar.setTime(date);
endOfWeek(calendar);
return calendar.getTime();
|
Calendar | firstDayOfLastWeek(Calendar c) first Day Of Last Week c = (Calendar) c.clone();
c.add(Calendar.WEEK_OF_YEAR, -1);
c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek());
return c;
|
Calendar | getADayOfWeek(Calendar day, int dayOfWeek) get A Day Of Week int week = day.get(Calendar.DAY_OF_WEEK); if (week == dayOfWeek) return day; int diffDay = dayOfWeek - week; if (week == Calendar.SUNDAY) { diffDay -= 7; } else if (dayOfWeek == Calendar.SUNDAY) { diffDay += 7; ... |
int | getDateOfLastDayOfWeekInMonth(Calendar calendar, int dayOfWeek) get Date Of Last Day Of Week In Month int lastDateOfMonth = getLastDateOfMonth(calendar); Calendar tmpCal = new GregorianCalendar(calendar.getTimeZone()); tmpCal.set(Calendar.YEAR, calendar.get(Calendar.YEAR)); tmpCal.set(Calendar.MONTH, calendar.get(Calendar.MONTH)); tmpCal.set(Calendar.DATE, lastDateOfMonth); int day = tmpCal.get(Calendar.DAY_OF_WEEK); if (day == dayOfWeek) { return tmpCal.get(Calendar.DATE); ... |
Calendar | getDayFromPreviousWeek(Calendar requestDate) get Day From Previous Week Calendar result = ((Calendar) requestDate.clone());
result.set(Calendar.DAY_OF_YEAR, (requestDate.get(Calendar.DAY_OF_YEAR) - 7));
return result;
|
int | getDayOfWeek(Calendar c) get Day Of Week switch (c.get(Calendar.DAY_OF_WEEK)) { case Calendar.SUNDAY: return 0; case Calendar.MONDAY: return 1; case Calendar.TUESDAY: return 2; case Calendar.WEDNESDAY: ... |
int | getDayOfWeek(Calendar cal) Quick hack to get day of week. if (cal.get(Calendar.DAY_OF_WEEK) > 1) { return cal.get(Calendar.DAY_OF_WEEK) - 1; return 7; |
int | getDayOfWeek(Calendar date) Returns the day of week depending if the week starts on sunday or monday. int day = date.get(Calendar.DAY_OF_WEEK); if (getFirstDayOfWeek() == Calendar.SUNDAY) return day - 1; else { if (day >= Calendar.MONDAY) return day - Calendar.MONDAY; else return 6; ... |
Integer | getDayOfWeekNumber(Calendar cal) get Day Of Week Number return cal.get(Calendar.DAY_OF_WEEK);
|