This method returns the value for the specified field from this Instance object.
package com.logicbig.example.instant;
import java.time.Instant;
import java.time.temporal.ChronoField;
public class GetExample {
public static void main(String... args) {
Instant i = Instant.now();
System.out.println(i);
for (ChronoField field : ChronoField.values()) {
try {
int v = i.get(field);
System.out.printf("%s > %s%n", field, v);
} catch (Exception e) {
System.out.printf(" -- %s not supported%n", field);
}
}
}
}
Output
2017-05-01T20:57:55.628Z
NanoOfSecond > 628000000
-- NanoOfDay not supported
MicroOfSecond > 628000
-- MicroOfDay not supported
MilliOfSecond > 628
-- 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 not supported
-- OffsetSeconds not supported