Home Java LocalDateTime Methods toLocalTime() Java LocalDateTime toLocalTime() Method 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.
LocalDateTime dt = LocalDateTime.of(2026, 3, 15, 14, 30, 45);
LocalTime time = dt.toLocalTime(); // 14:30:45 Call What 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.time.LocalDateTime
public LocalTime toLocalTime() Parameters Parameter Description None toLocalTime() takes no parameters.
Return Value Return Value Description LocalTimeThe time part of this date-time. It is never null.
Important
A LocalTime has no date, so it cannot say if a time is today or tomorrow. A time just after midnight is always "early", whatever the day. The text of a LocalTime also hides zero seconds, such as 14:30. The original LocalDateTime is not changed.
Compare with Similar Methods Related methods:
Java Examples 1. The time part 2. Opening hours 3. Reuse on another date 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.
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);
}
} time: 14:30:45
no seconds: 14:30
hour: 14
original: 2026-03-15T14:30:45 How It Works Two date-times. One has seconds, and the other has zero seconds.The time. toLocalTime() keeps the hour, minute, and second. The date is gone.Zero seconds are hidden. The second value prints as 14:30.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.
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"));
}
}
} 08:59 -> closed
09:00 -> open
16:59 -> open
17:00 -> closed How It Works Opening and closing times. They are LocalTime values, without a date.Visits on two days. The date does not matter for this check, only the time.The opening minute is open. !time.isBefore(opens) includes 09:00, but 08:59 is too early.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.
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));
}
} repeat: 2026-03-22T14:30
same as: true How It Works Split in two. The date and the time of the meeting are taken apart.Move the date. plusWeeks(1) on the LocalDate gives the same weekday one week later.Join them again. LocalDateTime.of(date, time) puts the new date together with the old time.Two ways, one result. date.atTime(time) gives the same date-time.Frequently Asked Questions How do I get the time from a LocalDateTime in Java? Call dt.toLocalTime(). It returns a LocalTime with the hour, minute, second, and nanosecond.
How do I combine a LocalDate and a LocalTime? Use LocalDateTime.of(date, time) or date.atTime(time).
Does toLocalTime() change the original object? No. LocalDateTime is immutable, so you get a new LocalTime and the original stays the same.
How do I check if a time is between two other times? Use !time.isBefore(start) && time.isBefore(end), with LocalTime values.
Why does the LocalTime print without seconds? When the seconds and the fraction are zero, toString() leaves them out, just as it does for a LocalDateTime.
About the author Developer, cloud engineer, and technical writer
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
Helpful Share Copy link Suggestion