This method checks if the provided TemporalField supported by this instance.
This methods check if the provided TemporalUnit is supported by this instance.
If this method returns true for the specified unit, then corresponding value can be added to, or subtracted from, this date. If false, then calling the plus and minus methods will throw an exception.
This example test the provided ChronoField for being supported.
package com.logicbig.example.localdate;
import java.time.LocalDate;
import java.time.temporal.ChronoField;
public class IsSupportedExample {
public static void main (String... args) {
LocalDate localDate = LocalDate.ofYearDay(1945, 200);
boolean b = localDate.isSupported(ChronoField.DAY_OF_MONTH);
System.out.println(b);
boolean b2 = localDate.isSupported(ChronoField.MINUTE_OF_HOUR);
System.out.println(b2);
}
}
Output
true
false
This example test the provided ChronoUnit for being supported.
package com.logicbig.example.localdate;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
public class IsSupportedExample2 {
public static void main (String... args) {
LocalDate localDate = LocalDate.ofYearDay(1945, 200);
boolean b = localDate.isSupported(ChronoUnit.DAYS);
System.out.println(b);
boolean b2 = localDate.isSupported(ChronoUnit.HALF_DAYS);
System.out.println(b2);
boolean b3 = localDate.isSupported(ChronoUnit.MICROS);
System.out.println(b3);
}
}
Output
true
false
false