The isTimeBased() method of ChronoUnit enum is used to check if this ChronoUnit is a time unit. All ChronoUnits from nanos to half-days are time-based.
Syntax:
public boolean isTimeBased()
Parameters: This method accepts nothing.
Return value: This method returns true if a time unit, false if a data unit.
Below programs illustrate the ChronoUnit.isTimeBased() method:
Program 1:
// Java program to demonstrate // ChronoUnit.isTimeBased() method import java.time.temporal.ChronoUnit; public class GFG { public static void main(String[] args) { // get ChronoUnit ChronoUnit chronoUnit = ChronoUnit.valueOf( "NANOS" ); // apply isTimeBased() boolean isTimeBasedAttribute = chronoUnit.isTimeBased(); // print System.out.println( "NANOS" + " is Date based attribute:" + isTimeBasedAttribute); } } |
NANOS is Date based attribute:true
Program 2:
// Java program to demonstrate // ChronoUnit.isTimeBased() method import java.time.temporal.ChronoUnit; public class GFG { public static void main(String[] args) { // get ChronoUnit ChronoUnit chronoUnit = ChronoUnit.valueOf( "DAYS" ); // apply isTimeBased() boolean isTimeBasedAttribute = chronoUnit.isTimeBased(); // print System.out.println( "DAYS" + " is Date based attribute:" + isTimeBasedAttribute); } } |
DAYS is Date based attribute:false
References: https://docs.oracle.com/javase/10/docs/api/java/time/temporal/ChronoUnit.html#isTimeBased()