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
FriChecking 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:
trueNotes
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
- LocalDate.of() — Creates a date from a year, month and day.
- DateTimeFormatter.ofPattern() — Creates a formatter for printing and parsing dates with a pattern such as dd.MM.yyyy.
Related recipes
In the tutorial
- Dates and times — The java.time package — LocalDate, LocalTime, LocalDateTime, date arithmetic, Period, Duration, ChronoUnit, time zones and Instant.