Java LocalDateTime getMonth() Method

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

Definition

In Java, getMonth() returns the month of a LocalDateTime as a Month, an enum with twelve values from JANUARY to DECEMBER.

An enum is easier to read than a number, and it works well in switch statements and comparisons with ==.

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);
Month month = dt.getMonth();   // MARCH
int number = month.getValue(); // 3
CallWhat it does
dt.getMonth()Returns the month as an enum, for example MARCH.
dt.getMonthValue()Returns the month as a number, 1 to 12.
month.getDisplayName(style, locale)Returns the name as text, such as March or Mar.
month.plus(n)Returns the month n months later, wrapping around the year.

Month has handy methods of its own, such as getValue(), plus(), minus(), and length().

Library declarations
Java
// java.time.LocalDateTime
public Month getMonth()

Parameters

ParameterDescription
NonegetMonth() takes no parameters.

Return Value

Return ValueDescription
MonthThe month as a Month enum: JANUARY to DECEMBER.

Compare with Similar Methods

Other ways to read part of a date-time:

MethodHow it differs
getMonthValue()Returns the same month as a number from 1 to 12.
withMonth(m)Sets the month instead of reading it.
getDayOfWeek()Reads the day of the week as an enum.

Java Examples

Example 1 — Print the Month and Its Number

Read the month of a date and print its enum name and number.

Java
import java.time.LocalDateTime;
import java.time.Month;

public class LdtGetMonthDemo {
    public static void main(String[] args) {
        LocalDateTime dt = LocalDateTime.of(2026, 3, 15, 10, 30);
        Month month = dt.getMonth();

        System.out.println("month:  " + month);
        System.out.println("number: " + month.getValue());
        System.out.println("is March: " + (month == Month.MARCH));
    }
}

How It Works

  1. An enum value. getMonth() returns Month.MARCH, and printing it shows the capital letters MARCH.
  2. getValue gives the number. The enum knows its own number, which is 3.
  3. Compare with ==. Enums are compared with ==, so the last line prints true.

Example 2 — Show a Friendly Month Name

Turn the enum into full and short text in English.

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

public class LdtGetMonthNames {
    public static void main(String[] args) {
        LocalDateTime dt = LocalDateTime.of(2026, 9, 1, 8, 0);
        Month month = dt.getMonth();

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

How It Works

  1. September. The date is 1 September 2026.
  2. FULL style. TextStyle.FULL with English gives "September".
  3. SHORT style. TextStyle.SHORT gives "Sep".
  4. plus(1) moves on. One month after September is OCTOBER.

Example 3 — Pick a Season with switch

Use the month enum in a switch statement to find the northern-hemisphere season.

Java
import java.time.LocalDateTime;

public class LdtGetMonthSeason {
    public static void main(String[] args) {
        LocalDateTime[] dates = {
            LocalDateTime.of(2026, 12, 25, 8, 0),
            LocalDateTime.of(2026, 4, 10, 8, 0),
            LocalDateTime.of(2026, 7, 4, 8, 0),
            LocalDateTime.of(2026, 10, 31, 8, 0)
        };

        for (LocalDateTime dt : dates) {
            String season;
            switch (dt.getMonth()) {
                case DECEMBER:
                case JANUARY:
                case FEBRUARY:
                    season = "winter";
                    break;
                case MARCH:
                case APRIL:
                case MAY:
                    season = "spring";
                    break;
                case JUNE:
                case JULY:
                case AUGUST:
                    season = "summer";
                    break;
                default:
                    season = "autumn";
            }
            System.out.println(dt.getMonth() + " -> " + season);
        }
    }
}

How It Works

  1. Switch on the enum. switch (dt.getMonth()) can use the month names as case labels, without the Month. prefix.
  2. Several cases share one result. December, January, and February all fall through to "winter".
  3. default covers the rest. The remaining months, September to November, are autumn.
  4. The output. December gives winter, April gives spring, July gives summer, and October gives autumn.

Frequently Asked Questions

Call dt.getMonth(). It returns a Month enum such as MARCH.
No. It only reads a value. LocalDateTime is immutable, so no method can change it.
Use dt.getMonth() for MARCH, or dt.getMonth().getDisplayName(TextStyle.FULL, Locale.ENGLISH) for March.
Month.MARCH is an enum value with a name and methods. Month.MARCH.getValue() returns 3.
Use dt.getMonth().plus(1). December plus 1 wraps around to JANUARY.

Next: getMonthValue()

Read the month as a number from 1 to 12.

getMonthValue() 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.

11 people found this page helpful