Java Day of Week isOnWeekend(Date date)

Here you can find the source of isOnWeekend(Date date)

Description

Uses the Calendar to see of the day of week is equal to saturday or sunday.

License

Apache License

Parameter

Parameter Description
date date to be checked

Return

return true only if the data falls on a saturday or a sunday.

Declaration

public static boolean isOnWeekend(Date date) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Calendar;
import java.util.Date;

public class Main {
    /**//from   w  ww  .  j  av a2  s .  c  om
     * Uses the {@link Calendar} to see of the day of week is equal to saturday or sunday.
     * @param date date to be checked
     * @return return true only if the data falls on a saturday or a sunday.
     */
    public static boolean isOnWeekend(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        return ((cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)
                || (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY));
    }
}

Related

  1. getWeekStartDateBeforeCurrent(int weekNum, Date current)
  2. getWeekth(String sDate)
  3. getYearOfWeek(Date date)
  4. incWeek(java.util.Date date, int amount, Locale locale)
  5. isMatchWeek(Date date, int week)
  6. isSameWeekDates(Date date1, Date date2)
  7. isWeekday(Date startDate)
  8. isWeekDay(final Date date)
  9. isWeekEnd(Date date)