Java Instant.getEpochSecond() Method with Examples

Tags: Java Instant Java 8

In this Java core tutorial we learn how to use the java.time.Instant.getEpochSecond() method to convert an Instant object into epoch seconds value in Java programming language.

How to use Instant.getEpochSecond() method

In Java, with a given Instant object we can use the Instant.getEpochSecond() to convert it to epoch seconds value which is a simple incrementing count of seconds where second 0 is 1970-01-01T00:00:00Z.

InstantGetEpochSecondExample1.java

import java.time.Instant;

public class InstantGetEpochSecondExample1 {
    public static void main(String... args) {
        Instant instant = Instant.parse("2022-07-11T08:00:30Z");

        long epochSecond = instant.getEpochSecond();

        System.out.println("Instant: " + instant);
        System.out.println("Epoch Second: " + epochSecond);
    }
}
The output as below.
Instant: 2022-07-11T08:00:30Z
Epoch Second: 1657526430

Happy Coding 😊

Java Instant.now() Method with Examples

Java Instant.ofEpochSecond() Method with Examples

Java Instant.ofEpochMilli() Method with Examples

Java Instant.parse() Method with Examples

Java Instant.getNano() Method with Examples

Java Instant.plusSeconds() Method with Examples

Java Instant.plusMillis() Method with Examples

Java Instant.plusNanos() Method with Examples

Java Instant.minusSeconds() Method with Examples

Java Instant.minusMillis() Method with Examples

Java Instant.minusNanos() Method with Examples

Java Instant.atOffset() Method with Examples

Java Instant.atZone() Method with Examples

Java Instant.toEpochMilli() Method with Examples

Java Instant.compareTo() Method with Examples

Java Instant.isAfter() Method with Examples

Java Instant.isBefore() Method with Examples

Java Instant.equals() Method with Examples

Java Instant.toString() Method with Examples

Java Compare two Instant Values