Java Convert Date to Instant

Tags: Java Date Java Instant

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

How to convert Date to Instant in Java

With a Date object we can use the Date.toInstant() method to get the Instant value of it as the following example Java program.

ConvertDateToInstantExample1.java

import java.time.Instant;
import java.util.Date;

public class ConvertDateToInstantExample1 {
    public static void main(String... args) {
        Date date = new Date();

        // Convert Date to Instant
        Instant instant = date.toInstant();

        System.out.println("Date: " + date);
        System.out.println("Instant: " + instant);
    }
}
The output as below.
Date: Sat Apr 16 16:52:29 ICT 2022
Instant: 2022-04-16T09:52:29.589Z

Happy Coding 😊

Java Convert Date to Milliseconds

Java Convert Date to String

Java Convert Date to Calendar

Java Date by Examples