Open In App

ChronoField isDateBased() method in Java with Examples

Improve
Improve
Like Article
Like
Save
Share
Report

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:




// Java program to demonstrate
// ChronoField.isDateBased() 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 isDateBased()
        boolean isDateBasedAttribute
            = chronoField.isDateBased();
  
        // print
        System.out.println(
            "HOUR_OF_DAY"
            + " is Date based attribute:"
            + isDateBasedAttribute);
    }
}


Output:

HOUR_OF_DAY is Date based attribute:false

Program 2:




// Java program to demonstrate
// ChronoField.isDateBased() 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 isDateBased()
        boolean isDateBasedAttribute
            = chronoField.isDateBased();
  
        // print
        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
Previous
Next
Share your thoughts in the comments
Similar Reads