Java Convert Instant to Epoch Milliseconds

Tags: Java Instant Java 8

In this Java core tutorial we learn how to convert a java.time.Instant object into an epoch milliseconds value in Java programming language.

How to convert Instant to Epoch Milliseconds in Java

In Java, with a given Instant object we can use the Instant.toEpochMilli() to return epoch milliseconds value which is the number of milliseconds from the epoch of 1970-01-01T00:00:00Z as the following example Java code.

ConvertInstantToEpochMillisecondsExample1.java

import java.time.Instant;

public class ConvertInstantToEpochMillisecondsExample1 {
    public static void main(String... args) {
        Instant instant = Instant.parse("2022-05-10T07:30:30.839996400Z");

        long epochMilliseconds = instant.toEpochMilli();

        System.out.println("Instant: " + instant);
        System.out.println("Epoch Milliseconds: " + epochMilliseconds);
    }
}
The output as below.
Instant: 2022-05-10T07:30:30.839996400Z
Epoch Milliseconds: 1652167830839

Happy Coding 😊

Java Convert Instant to Calendar

Java Convert Instant to Date

Java Convert Instant to LocalDateTime

Java Convert Instant to LocalDate

Java Convert Instant to LocalTime

Java Convert Instant to ZonedDateTime

Java Convert Instant to OffsetDateTime

Java Convert Instant to Epoch Seconds

Java Convert Instant to String

Java Convert String to Instant