This returns the value of the specified field in long.
package com.logicbig.example.instant;
import java.time.Instant;
import java.time.temporal.ChronoField;
public class GetLongExample {
public static void main(String... args) {
Instant i = Instant.now();
System.out.println(i);
for (ChronoField field : ChronoField.values()) {
try {
long v = i.getLong(field);
System.out.printf("%s > %s%n", field, v);
} catch (Exception e) {
System.out.printf(" -- %s not supported%n", field);
}
}
}
}
Output
2017-05-01T20:56:55.470Z
NanoOfSecond > 470000000
-- NanoOfDay not supported
MicroOfSecond > 470000
-- MicroOfDay not supported
MilliOfSecond > 470
-- 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 > 1493672215
-- OffsetSeconds not supported