LocalDate range() method in Java with Examples
The range() method of a LocalDate class is used to get the range of valid values for the field passes as a parameter. This method returns ValueRange object which contains the minimum and maximum valid values for a field. When the field is not supported then an exception is thrown. This LocalDate is helpful to enhance the accuracy of the returned range.
public ValueRange range(TemporalField field)
Parameters: This method accepts one single parameter field which is the field to query the range for.
Return value: This method returns ValueRange which is the range of valid values for the field, not null.
Exception: This method throws following Exceptions:
- DateTimeException – if the range for the field cannot be obtained.
- UnsupportedTemporalTypeException – if the field is not supported.
Below programs illustrate the range() method:
LocalDate: 2018-12-06 Range of DAY_OF_MONTH: 1 - 31
LocalDate: 2018-12-06 Range of DAY_OF_YEAR: 1 - 365
Please Login to comment...