Home Java LocalDateTime Methods toLocalDate() Java LocalDateTime toLocalDate() Method Definition In Java, dt.toLocalDate() returns a LocalDate with the year, month, and day of the date-time. The time of day 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);
LocalDate date = dt.toLocalDate(); // 2026-03-15 Call What it does dt.toLocalDate()The date part, as a LocalDate. dt.toLocalTime()The time part, as a LocalTime. date.atStartOfDay()Goes the other way: a date plus midnight. date.atTime(time)A date plus a time you choose.
Use it when you only care about "which day", for example to group events or to check a birthday.
Library declarations // java.time.LocalDateTime
public LocalDate toLocalDate() Parameters Parameter Description None toLocalDate() takes no parameters.
Return Value Return Value Description LocalDateThe date part of this date-time. It is never null.
Important
Because the time is dropped, two different date-times on the same day give equal dates. This is useful for grouping, but be careful if the exact moment matters. The original LocalDateTime is not changed.
Compare with Similar Methods Related methods:
Java Examples 1. The date part 2. Group by day 3. Same day? Example 1 — Get the Date Part of a Date-Time Take the date from a date-time, and check that the original is not changed.
import java.time.LocalDate;
import java.time.LocalDateTime;
public class LdtToLocalDateDemo {
public static void main(String[] args) {
LocalDateTime dt = LocalDateTime.of(2026, 3, 15, 14, 30, 45);
LocalDate date = dt.toLocalDate();
System.out.println("date: " + date);
System.out.println("day name: " + date.getDayOfWeek());
System.out.println("original: " + dt);
}
} date: 2026-03-15
day name: SUNDAY
original: 2026-03-15T14:30:45 How It Works A date-time with a time. It is 15 March 2026 at 14:30:45.The date. toLocalDate() keeps the year, month, and day. The time is gone.LocalDate has its own methods. Here getDayOfWeek() shows that 15 March 2026 is a Sunday.The original is unchanged. The last line still shows the full date-time.Example 2 — Count the Days in a List of Events Convert each event to its date, and collect the dates in a TreeSet to count the different days.
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
public class LdtToLocalDateGroup {
public static void main(String[] args) {
List<LocalDateTime> events = Arrays.asList(
LocalDateTime.of(2026, 3, 15, 9, 0),
LocalDateTime.of(2026, 3, 16, 11, 30),
LocalDateTime.of(2026, 3, 15, 18, 45),
LocalDateTime.of(2026, 3, 16, 8, 15),
LocalDateTime.of(2026, 3, 20, 12, 0)
);
Set<LocalDate> days = new TreeSet<>();
for (LocalDateTime event : events) {
days.add(event.toLocalDate());
}
System.out.println("events: " + events.size());
System.out.println("different days: " + days.size());
System.out.println(days);
}
} events: 5
different days: 3
[2026-03-15, 2026-03-16, 2026-03-20] How It Works Five events on three days. Some events share a day, but their times differ.Drop the time. toLocalDate() turns each event into a plain date.A set removes repeats. Equal dates are stored only once, so the five events leave three dates.A TreeSet sorts. The dates are printed in order, from the earliest to the latest.Example 3 — Check If Two Date-Times Are on the Same Day Compare a morning and an evening time, first as date-times, and then as dates.
import java.time.LocalDateTime;
public class LdtToLocalDateSameDay {
public static void main(String[] args) {
LocalDateTime morning = LocalDateTime.of(2026, 3, 15, 8, 0);
LocalDateTime evening = LocalDateTime.of(2026, 3, 15, 22, 0);
LocalDateTime nextDay = LocalDateTime.of(2026, 3, 16, 0, 5);
System.out.println("morning equals evening: " + morning.equals(evening));
System.out.println("same day (morning, evening): "
+ morning.toLocalDate().equals(evening.toLocalDate()));
System.out.println("same day (evening, next): "
+ evening.toLocalDate().equals(nextDay.toLocalDate()));
}
} morning equals evening: false
same day (morning, evening): true
same day (evening, next): false How It Works Three date-times. Two are on 15 March, and one is five minutes after midnight on the 16th.As date-times they differ. The times are different, so equals prints false.As dates they match. Both dates are 15 March, so the second line prints true.A new day is a new date. Even a few minutes after midnight makes the date different, so the last line is false.Frequently Asked Questions How do I get the date from a LocalDateTime in Java? Call dt.toLocalDate(). It returns a LocalDate with the year, month, and day.
How do I remove the time from a LocalDateTime? Use dt.toLocalDate() to get a LocalDate, or dt.truncatedTo(ChronoUnit.DAYS) to keep a LocalDateTime at midnight.
Does toLocalDate() change the original object? No. LocalDateTime is immutable, so you get a new LocalDate and the original stays the same.
How do I check if two LocalDateTime objects are on the same day? Compare their dates: a.toLocalDate().equals(b.toLocalDate()).
How do I turn a LocalDate back into a LocalDateTime? Use date.atStartOfDay() for midnight, or date.atTime(hour, minute) for a time you choose.
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.
10 people found this page helpful
Helpful Share Copy link Suggestion