Java Date Time - Instant ofEpochSecond(long epochSecond) example








Instant ofEpochSecond(long epochSecond) gets an instance of Instant using seconds from the epoch of 1970-01-01T00:00:00Z.

The nanosecond field is set to zero.

Syntax

ofEpochSecond has the following syntax.

public static Instant ofEpochSecond(long epochSecond)

Example

The following example shows how to use ofEpochSecond.

import java.time.Instant;

public class Main {
  public static void main(String[] args) {
    Instant instant = Instant.ofEpochSecond(123123123123L);
    System.out.println(instant.getEpochSecond());
    
  }
}

The code above generates the following result.