LocalDate isSupported() method in Java with Examples
Last Updated :
18 Dec, 2018
In LocalDate class, there are two types of isSupported() method depending upon the parameters passed to it.
isSupported(TemporalField field)
isSupported() method of a LocalDate class used to check if the specified field is supported by LocalDate class or not means using this method we can check if this LocalDate can be queried for the specified field.
The supported fields of ChronoField are:
- DAY_OF_WEEK
- ALIGNED_DAY_OF_WEEK_IN_MONTH
- ALIGNED_DAY_OF_WEEK_IN_YEAR
- DAY_OF_MONTH
- DAY_OF_YEAR
- EPOCH_DAY
- ALIGNED_WEEK_OF_MONTH
- ALIGNED_WEEK_OF_YEAR
- MONTH_OF_YEAR
- PROLEPTIC_MONTH
- YEAR_OF_ERA
- YEAR
- ERA
All other ChronoField instances will return false.
Syntax:
public boolean isSupported(TemporalField field)
Parameters: This method accepts one single parameter field which is the field to check.
Return value: This method returns boolean value true if the field is supported on this LocalDate, false if not.
Below programs illustrate the isSupported() method:
Program 1:
import java.time.*;
import java.time.temporal.ChronoField;
public class GFG {
public static void main(String[] args)
{
LocalDate lt
= LocalDate.parse( "2018-11-03" );
boolean value
= lt.isSupported(ChronoField.YEAR_OF_ERA);
System.out.println( "YEAR_OF_ERA Field is supported: "
+ value);
}
}
|
Output:
YEAR_OF_ERA Field is supported: true
isSupported(TemporalUnit unit)
isSupported() method of a LocalDate class used to Check if the specified unit is supported by LocalDate class or not means using this method we can check if this LocalDate can be queried for the specified unit.
The supported fields of ChronoUnit are:
- DAYS
- WEEKS
- MONTHS
- YEARS
- DECADES
- CENTURIES
- MILLENNIA
- ERAS
All other ChronoUnit instances will return false.
Syntax:
public boolean isSupported(TemporalUnit unit)
Parameters: This method accepts one single parameter unit which is the unit to check.
Return value: This method returns boolean value true if the field is supported on this LocalDate, false if not.
Below programs illustrate the isSupported() method:
Program 1:
import java.time.*;
import java.time.temporal.ChronoUnit;
public class GFG {
public static void main(String[] args)
{
LocalDate lt
= LocalDate.parse( "2018-12-29" );
boolean value
= lt.isSupported(ChronoUnit.CENTURIES);
System.out.println( "ChronoUnit CENTURIES is supported: "
+ value);
}
}
|
Output:
ChronoUnit CENTURIES is supported: true
Reference: https://docs.oracle.com/javase/10/docs/api/java/time/LocalDate.html#isSupported(java.time.temporal.TemporalField), https://docs.oracle.com/javase/10/docs/api/java/time/LocalDate.html#isSupported(java.time.temporal.TemporalUnit)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...