Java Instant getLong() method

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

This returns for the value of the specified field. If it is not possible to return the value because the field is not supported or for some other reason, it throws an exception.

Syntax

Parameters

field- The value for the field.

Return

The value of 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

Example 2

Output:

The output will be like this.
2018-08-10T06:00:07.269Z
NanoOfSecond > 269000000
    -- NanoOfDay not supported
MicroOfSecond > 269000
    -- MicroOfDay not supported
MilliOfSecond > 269
    -- MilliOfDay not supported
    -- SecondOfMinute not supported
    -- SecondOfDay not supported
    -- MinuteOfHour not supported
    -- MinuteOfDay not supported
    -- HourOfAmPm not supported
    -- ClockHourOfAmPm not supported
    -- HourOfDay not supported
    -- ClockHourOfDay not supported
    -- AmPmOfDay not supported
    -- DayOfWeek not supported
    -- AlignedDayOfWeekInMonth not supported
    -- AlignedDayOfWeekInYear not supported
    -- DayOfMonth not supported
    -- DayOfYear not supported
    -- EpochDay not supported
    -- AlignedWeekOfMonth not supported
    -- AlignedWeekOfYear not supported
    -- MonthOfYear not supported
    -- ProlepticMonth not supported
    -- YearOfEra not supported
    -- Year not supported
    -- Era not supported
InstantSeconds > 1533880807
    -- OffsetSeconds not supported