package com.logicbig.example.yearmonth;
import java.time.YearMonth;
import java.time.temporal.ChronoField;
public class IsSupportedExample {
public static void main(String... args) {
YearMonth y = YearMonth.of(2010, 7);
System.out.println(y);
for (ChronoField field : ChronoField.values()) {
boolean b = y.isSupported(field);
System.out.printf("%23s > %s%n", field, b);
}
}
}
Output
2010-07
NanoOfSecond > false
NanoOfDay > false
MicroOfSecond > false
MicroOfDay > false
MilliOfSecond > false
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 > true
ProlepticMonth > true
YearOfEra > true
Year > true
Era > true
InstantSeconds > false
OffsetSeconds > false
package com.logicbig.example.yearmonth;
import java.time.YearMonth;
import java.time.temporal.ChronoUnit;
public class IsSupportedExample2 {
public static void main(String... args) {
YearMonth y = YearMonth.of(2010, 11);
System.out.println(y);
for (ChronoUnit unit : ChronoUnit.values()) {
boolean b = y.isSupported(unit);
System.out.printf("%10s > %s%n", unit, b);
}
}
}
Output
2010-11
Nanos > false
Micros > false
Millis > false
Seconds > false
Minutes > false
Hours > false
HalfDays > false
Days > false
Weeks > false
Months > true
Years > true
Decades > true
Centuries > true
Millennia > true
Eras > true
Forever > false