Java LocalDateTime toLocalTime() Method

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

Definition

In Java, dt.toLocalTime() returns a LocalTime with the hour, minute, second, and nanosecond of the date-time. The date is dropped.

The date-time itself does not change, because LocalDateTime is immutable. You get a new, smaller object.

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 date-time. No arguments are needed.

Java
LocalDateTime dt = LocalDateTime.of(2026, 3, 15, 14, 30, 45);

LocalTime time = dt.toLocalTime();   // 14:30:45
CallWhat it does
dt.toLocalTime()The time part, as a LocalTime.
dt.toLocalDate()The date part, as a LocalDate.
LocalDateTime.of(date, time)Joins a date and a time back into a date-time.
date.atTime(time)The same join, written from the date.

Use it when you only care about the time of day, for example to check opening hours.

Library declarations
Java
// java.time.LocalDateTime
public LocalTime toLocalTime()

Parameters

ParameterDescription
NonetoLocalTime() takes no parameters.

Return Value

Return ValueDescription
LocalTimeThe time part of this date-time. It is never null.

Compare with Similar Methods

Related methods:

MethodHow it differs
toLocalDate()The other half: the date.
truncatedTo(unit)Keeps a LocalDateTime and cuts the small parts.
getHour()Gets only the hour, as an int.

Java Examples

Example 1 — Get the Time Part of a Date-Time

Take the time from a date-time, and see how it prints with and without seconds.

Java
import java.time.LocalDateTime;

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

        System.out.println("time:       " + dt.toLocalTime());
        System.out.println("no seconds: " + noSeconds.toLocalTime());
        System.out.println("hour:       " + dt.toLocalTime().getHour());
        System.out.println("original:   " + dt);
    }
}

How It Works

  1. Two date-times. One has seconds, and the other has zero seconds.
  2. The time. toLocalTime() keeps the hour, minute, and second. The date is gone.
  3. Zero seconds are hidden. The second value prints as 14:30.
  4. LocalTime has its own methods. getHour() gives 14, and the original date-time is unchanged.

Example 2 — Check Opening Hours

A shop is open from 09:00 up to, but not including, 17:00. Check several date-times against these hours.

Java
import java.time.LocalDateTime;
import java.time.LocalTime;

public class LdtToLocalTimeHours {
    public static void main(String[] args) {
        LocalTime opens = LocalTime.of(9, 0);
        LocalTime closes = LocalTime.of(17, 0);

        LocalDateTime[] visits = {
            LocalDateTime.of(2026, 3, 15, 8, 59),
            LocalDateTime.of(2026, 3, 15, 9, 0),
            LocalDateTime.of(2026, 3, 16, 16, 59),
            LocalDateTime.of(2026, 3, 16, 17, 0)
        };

        for (LocalDateTime visit : visits) {
            LocalTime time = visit.toLocalTime();
            boolean open = !time.isBefore(opens) && time.isBefore(closes);
            System.out.println(time + " -> " + (open ? "open" : "closed"));
        }
    }
}

How It Works

  1. Opening and closing times. They are LocalTime values, without a date.
  2. Visits on two days. The date does not matter for this check, only the time.
  3. The opening minute is open. !time.isBefore(opens) includes 09:00, but 08:59 is too early.
  4. The closing minute is closed. time.isBefore(closes) excludes 17:00, so 16:59 is the last open minute.

Example 3 — Reuse a Time on a Different Date

Take the time from one date-time, and join it with a new date.

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

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

        LocalTime time = meeting.toLocalTime();
        LocalDate nextWeek = meeting.toLocalDate().plusWeeks(1);

        LocalDateTime repeat = LocalDateTime.of(nextWeek, time);
        LocalDateTime sameThing = nextWeek.atTime(time);

        System.out.println("repeat:  " + repeat);
        System.out.println("same as: " + repeat.equals(sameThing));
    }
}

How It Works

  1. Split in two. The date and the time of the meeting are taken apart.
  2. Move the date. plusWeeks(1) on the LocalDate gives the same weekday one week later.
  3. Join them again. LocalDateTime.of(date, time) puts the new date together with the old time.
  4. Two ways, one result. date.atTime(time) gives the same date-time.

Frequently Asked Questions

Call dt.toLocalTime(). It returns a LocalTime with the hour, minute, second, and nanosecond.
Use LocalDateTime.of(date, time) or date.atTime(time).
No. LocalDateTime is immutable, so you get a new LocalTime and the original stays the same.
Use !time.isBefore(start) && time.isBefore(end), with LocalTime values.
When the seconds and the fraction are zero, toString() leaves them out, just as it does for a LocalDateTime.

Next: toString()

Get the date-time as ISO-8601 text such as 2026-03-15T10:30.

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