Encodera

Thanks for reading!

Donate to the site — we work hard for you.

Java reference

LocalDate.getDayOfWeek()

Returns the day of the week of a date.

Available since: Java 8

Syntax

public DayOfWeek getDayOfWeek()

Return value

DayOfWeekA DayOfWeek enum value: MONDAY … SUNDAY.

Examples

The weekday, its number and its name:

void main() {
    DayOfWeek day = LocalDate.of(2025, 3, 14).getDayOfWeek();
    IO.println(day);
    IO.println(day.getValue());
    IO.println(day.getDisplayName(TextStyle.SHORT, Locale.ENGLISH));
}

Output:

FRIDAY
5
Fri

Checking for a weekend:

void main() {
    LocalDate date = LocalDate.of(2025, 3, 15);
    DayOfWeek day = date.getDayOfWeek();
    boolean weekend = day == DayOfWeek.SATURDAY || day == DayOfWeek.SUNDAY;
    IO.println(weekend);
}

Output:

true

Notes

getValue() numbers days from Monday: 1 is Monday, 7 is Sunday. The next Monday after a date: date.with(TemporalAdjusters.next(DayOfWeek.MONDAY)).

See also

Related recipes

In the tutorial

  • Dates and times — The java.time package — LocalDate, LocalTime, LocalDateTime, date arithmetic, Period, Duration, ChronoUnit, time zones and Instant.

Thanks for reading!

Donate to the site — we work hard for you.