Close

Java Date Time - YearMonth.isSupported() Examples

Java Date Time Java Java API 


Class:

java.time.YearMonth

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

Methods:

public boolean isSupported(TemporalField field)

Checks if the specified field is supported by this YearMonth object.



public boolean isSupported(TemporalUnit unit)

Checks if the specified unit is supported by this YearMonth object.


Examples


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




See Also