ChronoField isDateBased() method in Java with Examples
The isDateBased() method of ChronoField enum is used to check that if this ChronoField represents a component of a date or not.ChronoField constants from day-of-week to era are date-based.
Syntax:
public boolean isDateBased()
Parameters: This method accepts nothing.
Return value: This method returns true if it is a component of a date.
Below programs illustrate the ChronoField.isDateBased() method:
Program 1:
import java.time.temporal.ChronoField;
public class GFG {
public static void main(String[] args)
{
ChronoField chronoField
= ChronoField.valueOf( "HOUR_OF_DAY" );
boolean isDateBasedAttribute
= chronoField.isDateBased();
System.out.println(
"HOUR_OF_DAY"
+ " is Date based attribute:"
+ isDateBasedAttribute);
}
}
|
Output:
HOUR_OF_DAY is Date based attribute:false
Program 2:
import java.time.temporal.ChronoField;
public class GFG {
public static void main(String[] args)
{
ChronoField chronoField
= ChronoField.valueOf( "YEAR_OF_ERA" );
boolean isDateBasedAttribute
= chronoField.isDateBased();
System.out.println( "YEAR_OF_ERA"
+ " is Date based attribute:"
+ isDateBasedAttribute);
}
}
|
Output:
YEAR_OF_ERA is Date based attribute:true
References: https://docs.oracle.com/javase/10/docs/api/java/time/temporal/ChronoField.html#isDateBased()
Last Updated :
29 Jan, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...