In Java, getDayOfWeek() returns the weekday of a LocalDateTime as a DayOfWeek, an enum with seven values from MONDAY to SUNDAY.
The week follows the ISO standard, so Monday is 1 and Sunday is 7. Use getValue() on the enum if you need the number.
An instance method of java.time.LocalDateTime (since Java 8): call it on a LocalDateTime object. Add import java.time.LocalDateTime; at the top of your file.
Syntax
Call it on a LocalDateTime. It takes no arguments.
Java
LocalDateTime dt = LocalDateTime.of(2026, 3, 15, 10, 30);
DayOfWeek day = dt.getDayOfWeek(); // SUNDAY
int number = day.getValue(); // 7
Call
What it does
dt.getDayOfWeek()
Returns the weekday as an enum, for example SUNDAY.
dt.getDayOfMonth()
Returns the number on the calendar page.
day.getValue()
Returns the weekday number: 1 for Monday to 7 for Sunday.
day.getDisplayName(style, locale)
Returns the name as text, such as Sunday or Sun.
DayOfWeek also has plus(n) and minus(n), which wrap around the week.
Library declarations
Java
// java.time.LocalDateTime
public DayOfWeek getDayOfWeek()
Parameters
Parameter
Description
None
getDayOfWeek() takes no parameters.
Return Value
Return Value
Description
DayOfWeek
The weekday as a DayOfWeek enum: MONDAY to SUNDAY.