Java Instant get() method

The get() method of Java Instant class is used to get the value of the specified field from this instant as an int.

It provides an instant result for the value of the specified field. The returned value will always be within the valid range of values for the field. If it is not possible to return the value because the field is not supported or for some other reason, it throw an exception.

Syntax

Parameters

field - The field to get, not null.

Return

The value for the field.

Exceptions

DateTimeException - If a value for the field cannot be obtained or the value is outside the range of valid values for the field.

UnsupportedTemporalTypeException - If the field is not supported or the range of values exceeds an int.

ArithmeticException - If numeric overflow occurs.

Example 1

Output:

The output will be like this.

0