Java Day of Week isWeekend(Date dt)

Here you can find the source of isWeekend(Date dt)

Description

Check whether a date is a weekend

License

Open Source License

Parameter

Parameter Description
dt The given Date

Return

boolean true if weekend, else false

Declaration

public static boolean isWeekend(Date dt) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**/*  ww  w . java2 s .c  om*/
     * Check whether a date is a weekend
     * 
     * @param dt
     *            The given Date
     * 
     * @return boolean true if weekend, else false
     */
    public static boolean isWeekend(Date dt) {
        return isSaturday(dt) || isSunday(dt);
    }

    /**
     * Check whether a date is Saturday
     * 
     * @param dt
     *            The given Date
     * 
     * @return boolean true if Saturday, else false
     */
    public static boolean isSaturday(Date dt) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(dt);
        int day = cal.get(Calendar.DAY_OF_WEEK);

        return (day == Calendar.SATURDAY) ? true : false;
    }

    /**
     * Check whether a date is Sunday
     * 
     * @param dt
     *            The given Date
     * 
     * @return boolean true if Sunday, else false
     */
    public static boolean isSunday(Date dt) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(dt);
        int day = cal.get(Calendar.DAY_OF_WEEK);

        return (day == Calendar.SUNDAY) ? true : false;
    }
}

Related

  1. isWeekend(Date date)
  2. isWeekend(Date date)
  3. isWeekend(Date date)
  4. isWeekend(Date date)
  5. isWeekend(Date date)
  6. isWeekEnd(Date in)
  7. isWeekend(final Date date)
  8. isWeekendDay(final DayOfWeek nDayOfWeek)
  9. isWork(String weekday, Date date)