Saturday, November 16, 2024
Google search engine
HomeLanguagesJavaChronoUnit isDateBased() method in Java with Examples

ChronoUnit isDateBased() method in Java with Examples

The isDateBased() method of ChronoUnit enum is used to check if this ChronoUnit is a date unit. All ChronoUnits from days to eras are date-based.

Syntax:

public boolean isDateBased()

Parameters: This method accepts nothing.

Return value: This method returns true if a date unit, false if a time unit.

Below programs illustrate the ChronoUnit.isDateBased() method:
Program 1:




// Java program to demonstrate
// ChronoUnit.isDateBased() method
  
import java.time.temporal.ChronoUnit;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // get ChronoUnit
        ChronoUnit chronoUnit
            = ChronoUnit.valueOf("DECADES");
  
        // apply isDateBased()
        boolean isDateBasedAttribute
            = chronoUnit.isDateBased();
  
        // print
        System.out.println(
            "DECADES"
            + " is Date based attribute:"
            + isDateBasedAttribute);
    }
}


Output:

DECADES is Date based attribute:true

Program 2:




// Java program to demonstrate
// ChronoUnit.isDateBased() method
  
import java.time.temporal.ChronoUnit;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // get ChronoUnit
        ChronoUnit chronoUnit
            = ChronoUnit.valueOf("MINUTES");
  
        // apply isDateBased()
        boolean isDateBasedAttribute
            = chronoUnit.isDateBased();
  
        // print
        System.out.println(
            "MINUTES"
            + " is Date based attribute:"
            + isDateBasedAttribute);
    }
}


Output:

MINUTES is Date based attribute:false

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

RELATED ARTICLES

Most Popular

Recent Comments