Java Instant getLong() 方法

2025年1月7日 | 阅读 2 分钟

Java Instant 类的 getLong() 方法用于从当前 Instant 获取指定字段的值,返回一个 long 类型的值。

此方法返回指定字段的值。如果由于字段不支持或出于其他原因无法返回该值,则会抛出异常。

语法

参数

field - 字段的值。

返回

字段的值。

异常

DateTimeException - 如果无法获取字段的值,或者该值超出了该字段的有效值范围。

UnsupportedTemporalTypeException - 如果字段不受支持或值的范围超过了 int。

ArithmeticException - 如果发生数值溢出。

示例 1

输出

输出将如下所示。

0

示例 2

输出

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