Java Day of Week isWeekend(Date date)

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

Description

is Weekend

License

LGPL

Declaration

public static boolean isWeekend(Date date) 

Method Source Code

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

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

public class Main {
    public static boolean isWeekend(Date date) {
        boolean result = false;
        int day = getDayOfWeek(date);
        result = false;//  w  ww .  j  av  a 2s.c  o m
        result = result || day == Calendar.SATURDAY;
        result = result || day == Calendar.SUNDAY;
        return result;
    }

    public static int getDayOfWeek(Date date) {
        return getField(date, Calendar.DAY_OF_WEEK);
    }

    public static int getField(Date date, int field) {
        int result = -1;
        if (date != null) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            result = calendar.get(field);
        }
        return result;
    }
}

Related

  1. isSameWeekDates(Date date1, Date date2)
  2. isWeekday(Date startDate)
  3. isWeekDay(final Date date)
  4. isWeekEnd(Date date)
  5. isWeekend(Date date)
  6. isWeekend(Date date)
  7. isWeekend(Date date)
  8. isWeekend(Date date)
  9. isWeekend(Date dt)