This method checks whether the given date object is representing a date at the weekend (Saturday or Sunday) - Java java.time

Java examples for java.time:Week

Description

This method checks whether the given date object is representing a date at the weekend (Saturday or Sunday)

Demo Code


//package com.java2s;
import java.time.DayOfWeek;
import java.time.LocalDate;

import java.time.temporal.ChronoField;

public class Main {
    /**/*  www .j  a  v a 2s  .com*/
     * This method checks whether the given date object is representing a date
     * at the weekend (Saturday or Sunday)
     * 
     * @param date
     *            Date to check, cannot be null
     * @return TRUE is Saturday or Sunday
     */
    public static boolean isWeekend(LocalDate date) {
        DayOfWeek dayOfWeek = DayOfWeek.of(date
                .get(ChronoField.DAY_OF_WEEK));
        switch (dayOfWeek) {
        case SATURDAY:
        case SUNDAY:
            return true;
        default:
            return false;
        }
    }
}

Related Tutorials