range() method of the LocalDateTime class is useful to get the minimum and maximum values as a ValueRange object for the field passed as a parameter to this method. This method returns ValueRange object only for those fields which are supported by LocalDate object. So when the field is not supported by this method then an exception is thrown by this method.
public ValueRange range(TemporalField field)
Parameters: This method accepts one parameter field which is the field to query the range.
Return value: This method returns the range of valid values for the field.
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:
Range in MILLI_OF_SECOND: 0 - 999
Range in DAY_OF_YEAR: 1 - 365
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.