The ofEpochMilli() method of Instant class helps to get an Instant using milliseconds passed as parameter from the epoch of 1970-01-01T00:00:00Z. This returned milliseconds is used to get the different time units like seconds, etc by conversion.
public static Instant ofEpochMilli(long epochMilli)
Parameters: This method accepts one parameter epochMilli is value of milliseconds from 1970-01-01T00:00:00Z.
Returns: This method returns Instant as the time from the Epoch as milliseconds.
Exception: This method throws DateTimeException if the result exceeds the maximum or minimum instant.
Below programs illustrate the ofEpochMilli() method:
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.