The range() method of a ChronoLocalDateTime interface is used to get the range of valid values for the field passes as a parameter. This method returns a ValueRange object which contains the minimum and maximum valid values for a field. This ChronoLocalDateTime is helpful to enhance the accuracy of the returned range. When the field is not supported and the method is unable to return range values then an exception is thrown.
default ValueRange range(TemporalField field)
Parameters: This method accepts one single parameter field which is the field to get range of values.
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:
ChronoLocalDateTime of Calcutta: 2018-10-25T23:12:31.123 Range of MILLI_OF_SECOND: 0 - 999
ChronoLocalDateTime of Calcutta: 2019-12-31T19:15:30 Range of NANO_OF_SECOND: 0 - 999999999
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.