ChronoField checkValidValue() method in Java with Examples
Last Updated :
29 Jan, 2020
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:
import java.time.temporal.ChronoField;
public class GFG {
public static void main(String[] args)
{
ChronoField chronoField
= ChronoField.valueOf( "MINUTE_OF_DAY" );
long validInt
= chronoField.checkValidValue( 360 );
System.out.println( "Value passed :"
+ validInt);
}
}
|
Output:
Value passed :360
Program 2:
import java.time.temporal.ChronoField;
public class GFG {
public static void main(String[] args)
{
ChronoField chronoField
= ChronoField.valueOf( "DAY_OF_WEEK" );
long validInt
= chronoField.checkValidValue( 2 );
System.out.println( "Value passed :"
+ validInt);
}
}
|
References: https://docs.oracle.com/javase/10/docs/api/java/time/temporal/ChronoField.html#checkValidValue(long)
Share your thoughts in the comments
Please Login to comment...