Sunday, December 29, 2024
Google search engine
HomeLanguagesJavaChronoUnit isTimeBased() method in Java with Examples

ChronoUnit isTimeBased() method in Java with Examples

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);
    }
}


Output:

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);
    }
}


Output:

DAYS is Date based attribute:false

References: https://docs.oracle.com/javase/10/docs/api/java/time/temporal/ChronoUnit.html#isTimeBased()

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments