Java LocalDateTime from() Method

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

Definition

In Java, LocalDateTime.from(temporal) converts another date-time object into a LocalDateTime. It works for any object that holds both a date and a time, such as a ZonedDateTime or an OffsetDateTime.

The zone or offset is simply dropped. You keep the date and the clock time as they were shown. If the object has no date or no time, the method throws an exception.

A static method of java.time.LocalDateTime (since Java 8): call it on the class, as LocalDateTime.from(), with no object needed. Add import java.time.LocalDateTime; at the top of your file.

Syntax

Pass the object to convert. The method is also handy as a method reference, LocalDateTime::from.

Java
ZonedDateTime zoned = ZonedDateTime.of(LocalDateTime.of(2026, 3, 15, 10, 30), ZoneId.of("Asia/Kolkata"));
LocalDateTime dt = LocalDateTime.from(zoned);   // 2026-03-15T10:30
CallWhat it does
LocalDateTime.from(zdt)Drops the zone from a ZonedDateTime.
LocalDateTime.from(odt)Drops the offset from an OffsetDateTime.
zdt.toLocalDateTime()The same conversion written as an instance method.
formatter.parse(text, LocalDateTime::from)Parses text and converts it in one step.

If you already know the exact type, zdt.toLocalDateTime() is shorter. from() is most useful when the type is general, as in TemporalAccessor.

Library declarations
Java
// java.time.LocalDateTime
public static LocalDateTime from(TemporalAccessor temporal)

Parameters

ParameterDescription
temporal (TemporalAccessor)The object to convert. It must hold both a date and a time.

Return Value

Return ValueDescription
LocalDateTimeThe date and time taken from the object, without any zone or offset.

Compare with Similar Methods

Other ways to get a LocalDateTime:

MethodHow it differs
ofInstant(instant, zone)Converts an Instant, which from() cannot do.
of(date, time)Joins a LocalDate and a LocalTime.
parse(text)Reads a date-time from text.

Java Examples

Example 1 — Drop the Zone from a ZonedDateTime

Convert a date-time with a zone into a plain LocalDateTime.

Java
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;

public class LdtFromDemo {
    public static void main(String[] args) {
        ZonedDateTime zoned = ZonedDateTime.of(LocalDateTime.of(2026, 3, 15, 10, 30), ZoneId.of("Asia/Kolkata"));
        LocalDateTime plain = LocalDateTime.from(zoned);

        System.out.println("zoned: " + zoned);
        System.out.println("plain: " + plain);
    }
}

How It Works

  1. A zoned date-time. It holds the date, the time, and the zone Asia/Kolkata.
  2. Convert it. LocalDateTime.from(zoned) keeps the date and the clock time.
  3. The zone is dropped. The first line shows the offset and the zone name in brackets. The second line shows only the date and time.

Example 2 — Use from with OffsetDateTime and as a Method Reference

Convert an OffsetDateTime, and then parse text and convert it with LocalDateTime::from.

Java
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;

public class LdtFromOffset {
    public static void main(String[] args) {
        OffsetDateTime offset = OffsetDateTime.of(LocalDateTime.of(2026, 3, 15, 10, 30), ZoneOffset.ofHours(2));
        System.out.println("from offset:  " + LocalDateTime.from(offset));

        LocalDateTime parsed = DateTimeFormatter.ISO_LOCAL_DATE_TIME.parse("2026-03-15T08:15:00", LocalDateTime::from);
        System.out.println("from parsing: " + parsed);
    }
}

How It Works

  1. An offset date-time. It holds the date, the time, and the offset +02:00.
  2. The offset is dropped. The first result is 10:30 with no offset.
  3. A method reference. LocalDateTime::from matches what parse(text, query) expects, so the formatter gives you a LocalDateTime directly.
  4. The parsed result. The second line shows 08:15, with the zero seconds hidden.

Example 3 — See What Cannot Be Converted

Try to convert a LocalDate, a LocalTime, and an Instant, which each miss a part.

Java
import java.time.DateTimeException;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

public class LdtFromFails {
    public static void main(String[] args) {
        try {
            LocalDateTime.from(LocalDate.of(2026, 3, 15));
        } catch (DateTimeException e) {
            System.out.println("LocalDate -> DateTimeException (no time)");
        }
        try {
            LocalDateTime.from(LocalTime.of(10, 30));
        } catch (DateTimeException e) {
            System.out.println("LocalTime -> DateTimeException (no date)");
        }
        try {
            LocalDateTime.from(Instant.parse("2026-03-15T10:30:00Z"));
        } catch (DateTimeException e) {
            System.out.println("Instant   -> DateTimeException (no zone)");
        }
    }
}

How It Works

  1. A LocalDate has no time. The method cannot make up the hour and minute, so it throws a DateTimeException.
  2. A LocalTime has no date. It fails the same way.
  3. An Instant has no zone. It is only a moment on the timeline, so Java does not know which wall clock to use. Use ofInstant() with a zone instead.

Frequently Asked Questions

Use zdt.toLocalDateTime() or LocalDateTime.from(zdt). Both keep the date and the clock time and drop the zone.
An Instant has no zone, so Java cannot work out the wall-clock time. Use LocalDateTime.ofInstant(instant, zone).
No. It keeps the clock time that the object shows, and only removes the zone or offset.
It is a method reference to this method. You can pass it where a TemporalQuery is expected, such as formatter.parse(text, LocalDateTime::from).
from() converts an existing date-time object. of() builds a new one from numbers or from a LocalDate and a LocalTime.

Next: get()

Read any field of the date-time as an int.

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

12 people found this page helpful