Java Convert LocalDateTime to LocalDate

Tags: Java LocalDateTime Java LocalDate Java 8

In This Java core tutorial we learn how to convert a java.time.LocalDateTime object to a java.time.LocalDate object in Java programming language.

How to convert LocalDateTime to LocalDate in Java

In Java with a given LocalDateTime object we can use the toLocalDate() method to get the date and returns LocalDate object. In the following Java program we learn how to use the LocalDateTime.toLocalDate() method to convert LocalDateTime to LocalDate.

ConvertLocalDateTimeToLocalDateExample1.java

import java.time.LocalDate;
import java.time.LocalDateTime;

public class ConvertLocalDateTimeToLocalDateExample1 {
    public static void main(String... args) {
        LocalDateTime localDateTime = LocalDateTime.now();
        LocalDate localDate = localDateTime.toLocalDate();

        System.out.println("LocalDateTime: " + localDateTime);
        System.out.println("LocalDate: " + localDate);
    }
}
The output as below.
LocalDateTime: 2022-04-24T11:07:30.189648
LocalDate: 2022-04-24

Happy Coding 😊

Java Convert LocalDateTime to String

Java Convert LocalDateTime to LocalTime

Java Convert LocalDateTime to OffsetDateTime

Java Convert LocalDateTime to ZonedDateTime

Java Convert LocalDateTime to Calendar

Java Convert LocalDateTime to Date

Java Convert LocalDateTime to Instant

Java Convert LocalDateTime to Epoch Seconds

Java Convert Epoch Seconds to LocalDateTime

Java Compare two LocalDateTime Values

Java Compare two LocalTime Values

Java LocalTime by Examples

Java LocalDate by Examples

Java LocalDateTime by Examples

Java Date by Examples

Java Calendar by Examples

Java Calendar using Calendar.Builder by Examples