Java Instant ofEpochSecond() method

The ofEpochSecond() method of Java Instant class is used to obtain an instance of Instant using seconds from the epoch of 1970-01-01T00:00:00Z The nanosecond field is set to zero.

Syntax

Parameters

epochSecond - The number of seconds from 1970-01-01T00:00:00Z

Return

An instant, not null.

Exceptions

DateTimeException - If the instant exceeds the maximum or minimum instant.

Example 1

Output:

The output will be like this.

1970-01-01T02:46:40Z

Example 2

Output:

The output will be like this.

123123123