Sunday, November 17, 2024
Google search engine
HomeLanguagesJavaChronoField checkValidIntValue() method in Java with Examples

ChronoField checkValidIntValue() method in Java with Examples

The checkValidIntValue() method of ChronoField enum is used to check that the value passed as parameter is valid for ChronoField constant or not and value fits in an integer or not.

Syntax:

public int checkValidIntValue(long value)

Parameters: This method accepts value which is the value to check.

Return value: This method returns the value that was passed in.

Below programs illustrate the ChronoField.checkValidIntValue() method:
Program 1:




// Java program to demonstrate
// ChronoField.checkValidIntValue() 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 checkValidIntValue()
        int validInt
            = chronoField.checkValidIntValue(21);
  
        // print
        System.out.println("Value passed :"
                           + validInt);
    }
}


Output:

Value passed :21

Program 2:




// Java program to demonstrate
// ChronoField.checkValidIntValue() 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 checkValidIntValue()
        int validInt
            = chronoField.checkValidIntValue(2021);
  
        // print
        System.out.println("Value passed :"
                           + validInt);
    }
}


Output:

Value passed :2021

References: https://docs.oracle.com/javase/10/docs/api/java/time/temporal/ChronoField.html#checkValidIntValue(long)

RELATED ARTICLES

Most Popular

Recent Comments