Java Convert Timestamp to LocalDateTime
Tags: Java Timestamp Java LocalDateTime Java 8
In this Java tutorial we learn how to convert a java.sql.Timestamp object to a java.time.LocalDateTime object in Java programming language.
How to convert Timestamp to LocalDateTime in Java
In Java, with a given Timestamp object we can use the Timestamp.toLocalDateTime() method to convert it to LocalDateTime object as the following example Java code.
ConvertTimestampToLocalDateTimeExample1.java
import java.sql.Timestamp;
import java.time.LocalDateTime;
public class ConvertTimestampToLocalDateTimeExample1 {
public static void main(String... args) {
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
// Convert Timestamp object to LocalDateTime object
LocalDateTime localDateTime = timestamp.toLocalDateTime();
System.out.println("Timestamp: " + timestamp);
System.out.println("LocalDateTime: " + localDateTime);
}
}
Timestamp: 2022-05-23 23:08:40.582
LocalDateTime: 2022-05-23T23:08:40.582
Happy Coding 😊
Related Articles
Java Convert ZonedDateTime to Timestamp
Java Convert LocalDate to Timestamp
Java Convert Instant to Timestamp
Java Convert LocalDateTime to Timestamp
Java Convert Timestamp to ZonedDateTime
Java Convert Timestamp to LocalDate
Java Convert Timestamp to Instant