Open In App

ChronoField checkValidValue() method in Java with Examples

Last Updated : 29 Jan, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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)



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads