Java Date Time - Instant ofEpochMilli(long epochMilli) example








Instant ofEpochMilli(long epochMilli) gets an instance of Instant using milliseconds from the epoch of 1970-01-01T00:00:00Z.

The seconds and nanoseconds are extracted from the specified milliseconds.

Syntax

ofEpochMilli has the following syntax.

public static Instant ofEpochMilli(long epochMilli)

Example

The following example shows how to use ofEpochMilli.

import java.time.Instant;

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

The code above generates the following result.