DayOfWeek Weekend Checks To Next Monday

Read the weekday of a LocalDate with getDayOfWeek, test SATURDAY and SUNDAY for weekend logic, and roll forward with TemporalAdjusters.next.

JavaData Integrity

Code

snippet
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;

public class WeekendGate {

    public static void main(String[] args) {
        LocalDate friday = LocalDate.of(2026, 11, 27);
        DayOfWeek dow = friday.getDayOfWeek();
        System.out.println("day: " + dow + " value: " + dow.getValue());

        // 加 1 天跨到周六:日期运算不懂工作日,周末要用 DayOfWeek 判断
        LocalDate saturday = friday.plusDays(1);
        boolean weekend = saturday.getDayOfWeek() == DayOfWeek.SATURDAY
                || saturday.getDayOfWeek() == DayOfWeek.SUNDAY;
        System.out.println(saturday + " is weekend: " + weekend);

        // 跳到下周一:plusDays 手推 3 天,或用 TemporalAdjusters.next
        System.out.println("next monday: " + saturday.with(TemporalAdjusters.next(DayOfWeek.MONDAY)));

        // DayOfWeek 不可变:plus/minus 返回新的枚举常量
        System.out.println("plus 2: " + dow.plus(2) + " minus 1: " + dow.minus(1));
    }
}

Watching the statements run

DayOfWeek Weekend Checks To Next Monday comes down to the class WeekendGate and the function main.

What to watch for

  • Nothing is fetched from outside the language; built-in APIs carry the whole example.

Using it

Signature: public static void main(String[] args)

The demo output is labeled (day:, next monday:, plus 2:); each label names the call that printed it.

Key statements

boolean weekend = saturday.getDayOfWeek() == DayOfWeek.SATURDAY
        || saturday.getDayOfWeek() == DayOfWeek.SUNDAY;
LocalDate friday = LocalDate.of(2026, 11, 27);
LocalDate saturday = friday.plusDays(1);

Interactive Tools for This Topic

FAQ

What does DayOfWeek Weekend Checks To Next Monday print when run?
Execute the whole file; each printed line is prefixed with a label like `day:`, `next monday:`, `plus 2:`.