Java Utililty Methods Weekend

List of utility methods to do Weekend

Description

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

Method

StringendOfWeek(Date date, String format)
end Of Week
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(endOfWeek(date));
IntegergetCalendarWeekOfDate(Date date)
get Calendar Week Of Date
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return new Integer(cal.get(Calendar.WEEK_OF_YEAR));
StringgetCurWeekEnd(String strDate)
get Cur Week End
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.parse(strDate, new ParsePosition(0));
Calendar calendar = dateFormat.getCalendar();
int day = calendar.get(Calendar.DAY_OF_WEEK);
calendar.add(Calendar.DATE, 7 - day);
return dateFormat.format(calendar.getTime());
ListgetWeekRange(String strBeginDate, String strEndDate, String pattern)
get Week Range
List<String> ret = new ArrayList<String>();
Date beginDate = parseDate(strBeginDate);
Date endDate = parseDate(strEndDate);
String beginFormat = formatDate(beginDate, pattern);
String endFormat = formatDate(endDate, pattern);
ret.add(beginFormat);
while (!beginFormat.equals(endFormat)) {
    beginDate = addWeek(beginDate, 1);
...
booleanisEndOfWeek()
is End Of Week
return getWeekNumByDate(getCurrentDate_String()) == 0;
booleanisWeekend(Calendar calendar)
Is date a weekend day?
int dayInWeek = calendar.get(Calendar.DAY_OF_WEEK);
return dayInWeek == Calendar.SATURDAY || dayInWeek == Calendar.SUNDAY;
booleanisWeekend(Calendar dateCal)
is Weekend
return (dateCal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
        || dateCal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY);
booleanisWeekend(Date date)
Function: SUNDAY or SATURDAY return true
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int weekday = calendar.get(Calendar.DAY_OF_WEEK);
if (weekday == Calendar.SUNDAY || weekday == Calendar.SATURDAY)
    return true;
return false;
booleanisWeekend(Date date)
Check if the date parameter occurs during a weekend.
if (date != null) {
    Calendar calendar = Calendar.getInstance();
    calendar.setFirstDayOfWeek(Calendar.MONDAY);
    calendar.setTime(date);
    int dayOfTheWeek = calendar.get(Calendar.DAY_OF_WEEK);
    return dayOfTheWeek == Calendar.SATURDAY || dayOfTheWeek == Calendar.SUNDAY;
} else {
    return false;
...
booleanisWeekEnd(Date datum)
is Week End
Calendar cal = new GregorianCalendar();
cal.setTime(datum);
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
return dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY;