Java Convert Instant to Timestamp

Tags: Java Instant Java Timestamp Java 8

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

How to convert Instant to Timestamp in Java

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

ConvertInstantToTimestampExample1.java

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

public class ConvertInstantToTimestampExample1 {
    public static void main(String... args) {
        Instant instant = Instant.now();

        Timestamp timestamp = Timestamp.from(instant);

        System.out.println("Instant: " + instant);
        System.out.println("Timestamp: " + timestamp);
    }
}
The output as below.
Instant: 2022-05-22T14:16:00.820514300Z
Timestamp: 2022-05-22 21:16:00.8205143

Happy Coding 😊

Java Convert ZonedDateTime to Timestamp

Java Convert LocalDate to Timestamp

Java Convert LocalDateTime to Timestamp

Java Convert Timestamp to LocalDateTime