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.
Code
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
Age CalculatorCalculate exact age in years, months, and days between a birth date and a reference date, plus total days and the next birthday countdown.Business Days CalculatorCount the weekdays between two dates, excluding weekends and any holidays you list, and see how many calendar and weekend days are involved.Cron Next Runs CalculatorCompute the next scheduled run times for a standard five-field cron expression, supporting ranges, lists, steps, and day-of-week naming semantics.ISO Week CalculatorFind the ISO 8601 week number, ISO week-year, week start and end dates, and day of year for any calendar date, with strict date validation.
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:`.
Report a problem with this exampleOpens a pre-filled issue on GitHub.