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

StringgetWeekDay(Calendar cal)
get Week Day
int Day_No = cal.get(Calendar.DAY_OF_WEEK);
String WeekDay = "Sunday";
switch (Day_No) {
case Calendar.SUNDAY: {
    WeekDay = "Sun";
    break;
case Calendar.MONDAY: {
...
intgetWeekdayPosition(Calendar jCalendar)
get Weekday Position
int weekOfMonth = jCalendar.get(Calendar.WEEK_OF_MONTH);
Calendar firstDayJCalendar = (Calendar) jCalendar.clone();
firstDayJCalendar.set(Calendar.DAY_OF_MONTH, 1);
if (firstDayJCalendar.get(Calendar.DAY_OF_WEEK) > jCalendar.get(Calendar.DAY_OF_WEEK)) {
    return weekOfMonth - 1;
return weekOfMonth;
CalendargetWeekEnd(boolean startSunday, Calendar date)
Returns a date corresponding to the last day of the week.
if (date == null) {
    date = new GregorianCalendar();
Calendar end = getWeekStart(startSunday, date);
end.add(Calendar.DAY_OF_MONTH, 6);
end.setTime(getDayEnd(end.getTime()));
return end;
intgetWeekOfCurrentDayWithoutStartShift(Calendar cal)
get Week Of Current Day Without Start Shift
int eventStartDay = cal.get(Calendar.DAY_OF_MONTH);
int eventWeekOfMonth = cal.get(Calendar.WEEK_OF_MONTH);
int eventRealWeekOfMonth = getRealWeekOfDay(eventStartDay);
return adjustWeekOfMonth(eventWeekOfMonth, eventRealWeekOfMonth);
CalendargetWeekStart(boolean startSunday, Calendar date)
Returns a date corresponding to the first day of the week.
Calendar start = new GregorianCalendar();
if (date != null) {
    start.setTime(date.getTime());
int current_dow = start.get(Calendar.DAY_OF_WEEK);
start.add(Calendar.DAY_OF_MONTH, -current_dow);
start.add(Calendar.DAY_OF_MONTH, startSunday ? Calendar.SUNDAY : Calendar.MONDAY);
start.setTime(getDayStart(start.getTime()));
...
booleanisThisWeek(Calendar time)
is This Week
if (time != null) {
    Calendar weekStart = getCalendar();
    snapStartOfWorkWeek(weekStart);
    Calendar weekEnd = getCalendar();
    snapEndOfWeek(weekEnd);
    return (time.compareTo(weekStart) >= 0 && time.compareTo(weekEnd) <= 0);
return false;
...
booleanisWeekday(Calendar cal)
is Weekday
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
return !(dayOfWeek < Calendar.MONDAY || dayOfWeek > Calendar.FRIDAY);
booleanisWeekEnd(Calendar c)
is Week End
int day = c.get(Calendar.DAY_OF_WEEK);
if (day == Calendar.SUNDAY || day == Calendar.SATURDAY) {
    return true;
return false;
booleanisWeekend(Calendar cal)
Gets the weekend attribute of the DateUtils class
return (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
        || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY);
booleanisWeekend(GregorianCalendar date)
is Weekend
return isSaturday(date) || isSunday(date);