Java LocalDateTime isSupported() Method

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

Definition

In Java, isSupported(...) returns true if a LocalDateTime can work with a given field or unit, and false if it cannot.

There are two versions: one takes a TemporalField (such as ChronoField.HOUR_OF_DAY) and one takes a TemporalUnit (such as ChronoUnit.DAYS). Asking first lets you avoid an UnsupportedTemporalTypeException.

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. It comes from TemporalAccessor, which LocalDateTime implements.

Syntax

Pass a field or a unit.

Java
LocalDateTime dt = LocalDateTime.of(2026, 3, 15, 14, 30);
boolean a = dt.isSupported(ChronoField.HOUR_OF_DAY);      // true
boolean b = dt.isSupported(ChronoField.OFFSET_SECONDS);   // false
boolean c = dt.isSupported(ChronoUnit.DAYS);              // true
CallWhat it does
dt.isSupported(field)Can this field be read or set?
dt.isSupported(unit)Can this unit be added, subtracted, or used with until()?
dt.get(field)Reads the field. Throws if it is not supported.
dt.plus(n, unit)Adds in the unit. Throws if it is not supported.

A LocalDateTime supports all date and time fields, but no zone fields. It supports every unit except FOREVER.

Library declarations
Java
// java.time.LocalDateTime
public boolean isSupported(TemporalField field)
public boolean isSupported(TemporalUnit unit)

Parameters

ParameterDescription
field (TemporalField)A field such as ChronoField.YEAR.
unit (TemporalUnit)A unit such as ChronoUnit.HOURS. Use one version or the other.

Return Value

Return ValueDescription
booleantrue if the field or unit can be used, false if not.

Compare with Similar Methods

Related methods:

MethodHow it differs
get(field)Reads the field once you know it is supported.
range(field)Tells you the valid values of a supported field.
plus(n, unit)Adds in a unit that must be supported.

Java Examples

Example 1 — Test Several Fields

Ask a date-time if it supports date, time, and zone fields.

Java
import java.time.LocalDateTime;
import java.time.temporal.ChronoField;

public class LdtIsSupportedFields {
    public static void main(String[] args) {
        LocalDateTime dt = LocalDateTime.of(2026, 3, 15, 14, 30);

        System.out.println("HOUR_OF_DAY:     " + dt.isSupported(ChronoField.HOUR_OF_DAY));
        System.out.println("DAY_OF_MONTH:    " + dt.isSupported(ChronoField.DAY_OF_MONTH));
        System.out.println("OFFSET_SECONDS:  " + dt.isSupported(ChronoField.OFFSET_SECONDS));
        System.out.println("INSTANT_SECONDS: " + dt.isSupported(ChronoField.INSTANT_SECONDS));
    }
}

How It Works

  1. Time and date fields. HOUR_OF_DAY and DAY_OF_MONTH are part of a LocalDateTime, so they are supported.
  2. Zone fields. OFFSET_SECONDS and INSTANT_SECONDS need a zone or an offset, which a LocalDateTime does not have.
  3. Nothing is thrown. The method only answers true or false.

Example 2 — Test Several Units

Ask which units a date-time accepts.

Java
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

public class LdtIsSupportedUnits {
    public static void main(String[] args) {
        LocalDateTime dt = LocalDateTime.of(2026, 3, 15, 14, 30);

        System.out.println("HOURS:   " + dt.isSupported(ChronoUnit.HOURS));
        System.out.println("MONTHS:  " + dt.isSupported(ChronoUnit.MONTHS));
        System.out.println("FOREVER: " + dt.isSupported(ChronoUnit.FOREVER));
    }
}

How It Works

  1. Normal units. A LocalDateTime can add or subtract hours and months.
  2. FOREVER is the exception. It means "no end", so you cannot add it to a date-time.
  3. The unit version. It takes a ChronoUnit, which is a different type of argument from a ChronoField.

Example 3 — Read a Field Only If It Is Supported

Loop over some fields and read only those that the date-time supports.

Java
import java.time.LocalDateTime;
import java.time.temporal.ChronoField;

public class LdtIsSupportedSafe {
    public static void main(String[] args) {
        LocalDateTime dt = LocalDateTime.of(2026, 3, 15, 14, 30);
        ChronoField[] fields = {ChronoField.HOUR_OF_DAY, ChronoField.OFFSET_SECONDS, ChronoField.DAY_OF_YEAR};

        for (ChronoField field : fields) {
            if (dt.isSupported(field)) {
                System.out.println(field + ": " + dt.getLong(field));
            } else {
                System.out.println(field + ": not supported");
            }
        }
    }
}

How It Works

  1. Three fields. One of them, OFFSET_SECONDS, is not part of a LocalDateTime.
  2. Ask first. The if calls isSupported() before reading.
  3. Supported fields are read. The hour is 14 and the day of the year is 74.
  4. No exception. The unsupported field takes the else branch, so the program never fails.

Frequently Asked Questions

Call dt.isSupported(ChronoField.X) before you read it, for example dt.isSupported(ChronoField.OFFSET_SECONDS).
A LocalDateTime has no zone or offset. Use ZonedDateTime or OffsetDateTime if you need it.
ChronoUnit.FOREVER. All the other ChronoUnit values are supported.
A field is a part of a date-time, such as HOUR_OF_DAY. A unit is a length of time, such as HOURS, used to add, subtract, or measure.
No. It returns true or false. The exception happens later if you use an unsupported field or unit anyway.

Next: minus()

Subtract an amount in any unit, or subtract a Duration or a Period.

minus() 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