Close

Java Date Time - Instant.isSupported() Examples

Java Date Time Java Java API 


Class:

java.time.Instant

java.lang.Objectjava.lang.Objectjava.time.Instantjava.time.Instantjava.time.temporal.TemporalTemporaljava.time.temporal.TemporalAdjusterTemporalAdjusterjava.lang.ComparableComparablejava.io.SerializableSerializableLogicBig

Methods:

public boolean isSupported(TemporalField field)

Checks if the specified field is supported.


Examples


package com.logicbig.example.instant;

import java.time.Instant;
import java.time.temporal.ChronoField;

public class IsSupportedExample {

public static void main(String... args) {
Instant i = Instant.now();
System.out.println(i);

for (ChronoField field : ChronoField.values()) {
boolean v = i.isSupported(field);
System.out.printf("%23s > %s%n", field, v);
}
}
}

Output

2017-05-01T20:57:45.145Z
NanoOfSecond > true
NanoOfDay > false
MicroOfSecond > true
MicroOfDay > false
MilliOfSecond > true
MilliOfDay > false
SecondOfMinute > false
SecondOfDay > false
MinuteOfHour > false
MinuteOfDay > false
HourOfAmPm > false
ClockHourOfAmPm > false
HourOfDay > false
ClockHourOfDay > false
AmPmOfDay > false
DayOfWeek > false
AlignedDayOfWeekInMonth > false
AlignedDayOfWeekInYear > false
DayOfMonth > false
DayOfYear > false
EpochDay > false
AlignedWeekOfMonth > false
AlignedWeekOfYear > false
MonthOfYear > false
ProlepticMonth > false
YearOfEra > false
Year > false
Era > false
InstantSeconds > true
OffsetSeconds > false




package com.logicbig.example.instant;

import java.time.Instant;
import java.time.temporal.ChronoUnit;

public class IsSupportedExample2 {

public static void main(String... args) {
Instant i = Instant.now();
System.out.println(i);

for (ChronoUnit unit : ChronoUnit.values()) {
boolean v = i.isSupported(unit);
System.out.printf("%12s > %s%n", unit, v);
}
}
}

Output

2017-05-01T20:57:47.276Z
Nanos > true
Micros > true
Millis > true
Seconds > true
Minutes > true
Hours > true
HalfDays > true
Days > true
Weeks > false
Months > false
Years > false
Decades > false
Centuries > false
Millennia > false
Eras > false
Forever > false




See Also