Java Convert Timestamp to Instant

Tags: Java Timestamp Java Instant Java 8

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

How to convert Timestamp to Instant in Java

In Java, with a given Timestamp object we can use the Timestamp.toInstant() method to convert it to Instant object as the following example Java code.

ConvertTimestampToInstantExample1.java

import java.sql.Timestamp;
import java.time.Instant;

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

        // Convert Timestamp object to Instant object
        Instant instant = timestamp.toInstant();

        System.out.println("Timestamp: " + timestamp);
        System.out.println("Instant: " + instant);
    }
}
The output as below.
Timestamp: 2022-05-24 18:38:42.174
Instant: 2022-05-24T11:38:42.174Z

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 LocalDate

Java Convert Timestamp to OffsetDateTime

Java Convert OffsetDateTime to Timestamp