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