Java Convert Instant to Epoch Seconds

Tags: Java Instant Java 8

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

How to convert Instant to Epoch Seconds in Java

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

ConvertInstantToEpochSecondsExample1.java

import java.time.Instant;

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

        long epochSeconds = instant.getEpochSecond();

        System.out.println("Instant: " + instant);
        System.out.println("Epoch Seconds: " + epochSeconds);
    }
}
The output as below.
Instant: 2022-05-10T07:30:30Z
Epoch Seconds: 1652167830

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 Milliseconds

Java Convert Instant to String

Java Convert String to Instant