Java Convert Timestamp to LocalDate

Tags: Java Timestamp Java LocalDate Java 8

In this Java core tutorial we learn how to convert a java.sql.Timestamp object to a java.time.LocalDate object in Java programming language.

How to convert Timestamp to LocalDate in Java

In Java, with a given Timestamp object we can follow these step to convert it to a LocalDate object.

  • Step 1: use the Timestamp.toLocalDateTime() method to convert the Timestamp object to a LocalDateTime object.
  • Step 1: use the LocalDateTime.toLocalDate() method to convert the LocalDateTime object of step 1 to a LocalDate object.

ConvertTimestampToLocalDateExample1.java

import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.LocalDateTime;

public class ConvertTimestampToLocalDateExample1 {
    public static void main(String... args) {
        Timestamp timestamp = new Timestamp(System.currentTimeMillis());

        // Convert Timestamp object to LocalDate object
        LocalDateTime localDateTime = timestamp.toLocalDateTime();
        LocalDate localDate = localDateTime.toLocalDate();

        System.out.println("Timestamp: " + timestamp);
        System.out.println("LocalDate: " + localDate);
    }
}
The output as below.
Timestamp: 2022-05-24 13:27:27.16
LocalDate: 2022-05-24

Happy Coding 😊

Java Convert ZonedDateTime to Timestamp

Java Convert LocalDate to Timestamp

Java Convert Instant to Timestamp

Java Convert LocalDateTime to Timestamp

Java Convert Timestamp to LocalDateTime

Java Convert Timestamp to ZonedDateTime

Java Convert Timestamp to Instant

Java Convert Timestamp to OffsetDateTime

Java Convert OffsetDateTime to Timestamp