Monday, November 18, 2024
Google search engine
HomeLanguagesJavaChronoField isTimeBased() method in Java with Examples

ChronoField isTimeBased() method in Java with Examples

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:




// Java program to demonstrate
// ChronoField.isTimeBased() method
  
import java.time.temporal.ChronoField;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // get chronoField
        ChronoField chronoField
            = ChronoField.valueOf("HOUR_OF_DAY");
  
        // apply isTimeBased()
        boolean isTimeBasedAttribute
            = chronoField.isTimeBased();
  
        // print
        System.out.println(
            "HOUR_OF_DAY"
            + " is Time based attribute:"
            + isTimeBasedAttribute);
    }
}


Output:

HOUR_OF_DAY is Time based attribute:true

Program 2:




// Java program to demonstrate
// ChronoField.isTimeBased() method
  
import java.time.temporal.ChronoField;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // get chronoField
        ChronoField chronoField
            = ChronoField.valueOf("YEAR_OF_ERA");
  
        // apply isTimeBased()
        boolean isTimeBasedAttribute
            = chronoField.isTimeBased();
  
        // print
        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()

RELATED ARTICLES

Most Popular

Recent Comments