Java Utililty Methods Calendar Week

List of utility methods to do Calendar Week

Description

The list of methods to do Calendar Week are organized into topic(s).

Method

StringgetDayOfWeekString1(Calendar currentDate)
Method getDayOfWeekString1.
int temp = getDayOfWeek(currentDate);
String result = "";
switch (temp) {
case Calendar.MONDAY:
    result = "A";
    break;
case Calendar.TUESDAY:
    result = "B";
...
DategetEndOfWeek(Calendar calendar, Date date, int dayStartOfWeek)
get End Of Week
ensureStateValid(calendar, date);
calendar.setTime(date);
setDateToZeroHour(calendar);
do {
    calendar.add(Calendar.DATE, 1);
} while (calendar.get(Calendar.DAY_OF_WEEK) != dayStartOfWeek);
calendar.add(Calendar.MILLISECOND, -1);
return calendar.getTime();
...
intgetFirstDateInMonthForDayOfWeek(Calendar cal, final int dayOfWeek)
get First Date In Month For Day Of Week
Calendar tmpCal = new GregorianCalendar(cal.getTimeZone());
tmpCal.set(Calendar.YEAR, cal.get(Calendar.YEAR));
tmpCal.set(Calendar.MONTH, cal.get(Calendar.MONTH));
tmpCal.set(Calendar.DATE, 1);
int day = tmpCal.get(Calendar.DAY_OF_WEEK);
if (day == dayOfWeek) {
    return tmpCal.get(Calendar.DATE);
while (day != dayOfWeek) {
    tmpCal.add(Calendar.DATE, 1);
    day = tmpCal.get(Calendar.DAY_OF_WEEK);
return tmpCal.get(Calendar.DATE);
CalendargetFirstDayOfWeek(Calendar cal)
get First Day Of Week
switch (cal.get(Calendar.DAY_OF_WEEK)) {
case 1:
    break;
case 2:
    cal.add(Calendar.DATE, -1);
    break;
case 3:
    cal.add(Calendar.DATE, -2);
...
CalendargetFirstDayOfWeek(Calendar calendar)
get First Day Of Week
Calendar ret = (Calendar) calendar.clone();
ret.add(Calendar.DAY_OF_MONTH, -((ret.get(Calendar.DAY_OF_WEEK) + 5) % 7));
return ret;
intgetFirstOfMonthDayOfWeek(GregorianCalendar aCalendar)
Gets the day of the week for the first day of the month.
int currDom = aCalendar.get(Calendar.DAY_OF_MONTH);
aCalendar.set(Calendar.DAY_OF_MONTH, 1);
int firstDowInMonth = aCalendar.get(Calendar.DAY_OF_WEEK);
aCalendar.set(Calendar.DAY_OF_MONTH, currDom);
return firstDowInMonth;
CalendargetImmediateDayOfWeek(Calendar current, int dayOfWeek)
get Immediate Day Of Week
Calendar immediateDayOfWeek = (Calendar) current.clone();
immediateDayOfWeek.add(Calendar.DAY_OF_MONTH, 1);
while (immediateDayOfWeek.get(Calendar.DAY_OF_WEEK) != dayOfWeek) {
    immediateDayOfWeek.add(Calendar.DAY_OF_MONTH, 1);
return immediateDayOfWeek;
intgetLastDayOfWeek(Calendar cal)
get Last Day Of Week
int last = cal.getFirstDayOfWeek() - 1;
if (last == 0) {
    last = Calendar.SATURDAY;
return last;
intgetLastDayOfWeek(Calendar cal)
get Last Day Of Week
int firstDayOfWeek = cal.getFirstDayOfWeek();
if (firstDayOfWeek == Calendar.SUNDAY) {
    return Calendar.SATURDAY;
} else if (firstDayOfWeek == Calendar.MONDAY) {
    return Calendar.SUNDAY;
} else if (firstDayOfWeek == Calendar.TUESDAY) {
    return Calendar.MONDAY;
} else if (firstDayOfWeek == Calendar.WEDNESDAY) {
...
intgetWeek(Calendar calendar)
get Week
return calendar.get(Calendar.WEEK_OF_YEAR);