Java LocalDateTime getDayOfWeek() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Java 8+

Definition

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
CallWhat 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

ParameterDescription
NonegetDayOfWeek() takes no parameters.

Return Value

Return ValueDescription
DayOfWeekThe weekday as a DayOfWeek enum: MONDAY to SUNDAY.

Compare with Similar Methods

Other ways to read part of a date-time:

MethodHow it differs
getDayOfMonth()Reads the day number of the month.
getDayOfYear()Reads the day number of the year.
getMonth()Reads the month as an enum.

Java Examples

Example 1 — Find the Weekday of a Date

Read the weekday of a date and print its name and number.

Java
import java.time.DayOfWeek;
import java.time.LocalDateTime;

public class LdtGetDayOfWeekDemo {
    public static void main(String[] args) {
        LocalDateTime dt = LocalDateTime.of(2026, 3, 15, 10, 30);
        DayOfWeek day = dt.getDayOfWeek();

        System.out.println("day:    " + day);
        System.out.println("number: " + day.getValue());
        System.out.println("is Sunday: " + (day == DayOfWeek.SUNDAY));
    }
}

How It Works

  1. An enum value. 15 March 2026 is a Sunday, so the enum prints as SUNDAY.
  2. Sunday is 7. In the ISO week, Monday is 1 and Sunday is the last day, 7.
  3. Compare with ==. The last line prints true.

Example 2 — Detect the Weekend

Loop over four days in a row and say if each one is a weekend day.

Java
import java.time.DayOfWeek;
import java.time.LocalDateTime;

public class LdtGetDayOfWeekWeekend {
    public static void main(String[] args) {
        LocalDateTime day = LocalDateTime.of(2026, 3, 13, 9, 0);

        for (int i = 0; i < 4; i++) {
            DayOfWeek d = day.getDayOfWeek();
            boolean weekend = d == DayOfWeek.SATURDAY || d == DayOfWeek.SUNDAY;
            System.out.println(d + " weekend: " + weekend);
            day = day.plusDays(1);
        }
    }
}

How It Works

  1. Start on Friday. 13 March 2026 is a Friday.
  2. Test each weekday. A day is a weekend day when it is SATURDAY or SUNDAY.
  3. Move to the next day. plusDays(1) prepares the next round of the loop.
  4. The results. Friday is false, Saturday and Sunday are true, and Monday is false.

Example 3 — Show Friendly Day Names

Print the full and short English names, and the next day.

Java
import java.time.DayOfWeek;
import java.time.LocalDateTime;
import java.time.format.TextStyle;
import java.util.Locale;

public class LdtGetDayOfWeekNames {
    public static void main(String[] args) {
        LocalDateTime dt = LocalDateTime.of(2026, 3, 15, 10, 30);
        DayOfWeek day = dt.getDayOfWeek();

        System.out.println("full:  " + day.getDisplayName(TextStyle.FULL, Locale.ENGLISH));
        System.out.println("short: " + day.getDisplayName(TextStyle.SHORT, Locale.ENGLISH));
        System.out.println("next:  " + day.plus(1));
    }
}

How It Works

  1. Sunday. The date falls on a Sunday.
  2. FULL style. TextStyle.FULL with English gives "Sunday".
  3. SHORT style. TextStyle.SHORT gives "Sun".
  4. plus(1) wraps around. The day after Sunday is MONDAY, the start of the next ISO week.

Frequently Asked Questions

Call dt.getDayOfWeek(). It returns a DayOfWeek enum such as SUNDAY.
No. It only reads a value. LocalDateTime is immutable, so no method can change it.
Use dt.getDayOfWeek(). It returns an enum such as SUNDAY.
7. Monday is 1 and Sunday is 7 in the ISO week used by java.time.
Compare dt.getDayOfWeek() with DayOfWeek.SATURDAY and DayOfWeek.SUNDAY.

Next: getDayOfYear()

Read the day number inside the year, from 1 to 366.

getDayOfYear() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

15 people found this page helpful