Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Java

DayOfWeek — days of the week

DayOfWeek represents the seven days of the week. DayOfWeek.MONDAY means Monday, whose ISO numeric value is 1.

Version: Java SE 21; repository runtime, production runtime not attested

Syntax

import java.time.DayOfWeek;
DayOfWeek day = DayOfWeek.MONDAY;

DayOfWeek in java.time is an enum representing the seven days of the week. The constant DayOfWeek.MONDAY means Monday.

getValue() returns the ISO number: 1 for Monday through 7 for Sunday. Do not use ordinal() for this. DayOfWeek.of(1) returns DayOfWeek.MONDAY; a number outside 1–7 causes DateTimeException.

plus(long) calculates cyclically, wrapping from Sunday to Monday. It does not change the original value. The example shows the constant name, ISO number, a six-day shift, and a comparison.

Examples

import java.time.DayOfWeek;

public class Main {
    public static void main(String[] args) {
        DayOfWeek day = DayOfWeek.MONDAY;
        System.out.println(day.name());
        System.out.println(day.getValue());
        System.out.println(day.plus(6).name());
        System.out.println(DayOfWeek.of(1) == day);
    }
}

Result

MONDAY
1
SUNDAY
true

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources