Close

Java Date Time - LocalDate.isSupported() Examples

Java Date Time Java Java API 


Class:

java.time.LocalDate

java.lang.Objectjava.lang.Objectjava.time.LocalDatejava.time.LocalDatejava.time.temporal.TemporalTemporaljava.time.temporal.TemporalAdjusterTemporalAdjusterjava.time.chrono.ChronoLocalDateChronoLocalDatejava.io.SerializableSerializableLogicBig

Methods:

public boolean isSupported(TemporalField field)

This method checks if the provided TemporalField supported by this instance.

If this method returns false, then calling the range, get and with methods will throw an exception.


public boolean isSupported(TemporalUnit unit)

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.


Examples


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




See Also