Java Weekend isWeekend(Date date)

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

Description

Check if the date parameter occurs during a weekend.

License

Apache License

Return

true or false

Declaration

public static boolean isWeekend(Date date) 

Method Source Code

//package com.java2s;
/**/*from w ww.j a  v  a  2  s  .c o m*/
 * Copyright (C) 2016 Hurence (support@hurence.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.*;

public class Main {
    /**
     * Check if the date parameter occurs during a weekend.
     *
     * @return true or false
     */
    public static boolean isWeekend(Date date) {
        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;
        }

    }
}

Related

  1. getCurWeekEnd(String strDate)
  2. getWeekRange(String strBeginDate, String strEndDate, String pattern)
  3. isEndOfWeek()
  4. isWeekend(Calendar calendar)
  5. isWeekend(Calendar dateCal)
  6. isWeekend(Date date)
  7. isWeekEnd(Date datum)
  8. IsWeekEnd(GregorianCalendar aInCal)
  9. isWeekend(String date)