Sunday, December 29, 2024
Google search engine
HomeLanguagesJavaChronoField checkValidValue() method in Java with Examples

ChronoField checkValidValue() method in Java with Examples

The checkValidValue() method of ChronoField enum is used to check that the value passed as parameter is valid for ChronoField constant or not.

Syntax:

public long checkValidValue(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.checkValidValue() method:
Program 1:




// Java program to demonstrate
// ChronoField.checkValidValue() method
  
import java.time.temporal.ChronoField;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // get chronoField
        ChronoField chronoField
            = ChronoField.valueOf("MINUTE_OF_DAY");
  
        // apply checkValidValue()
        long validInt
            = chronoField.checkValidValue(360);
  
        // print
        System.out.println("Value passed :"
                           + validInt);
    }
}


Output:

Value passed :360

Program 2:




// Java program to demonstrate
// ChronoField.checkValidValue() method
  
import java.time.temporal.ChronoField;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // get chronoField
        ChronoField chronoField
            = ChronoField.valueOf("DAY_OF_WEEK");
  
        // apply checkValidValue()
        long validInt
            = chronoField.checkValidValue(2);
  
        // print
        System.out.println("Value passed :"
                           + validInt);
    }
}


Output:

Value passed :2

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

RELATED ARTICLES

Most Popular

Recent Comments