ChronoZonedDateTime range() method in Java with Examples
The range() method of a ChronoZonedDateTime interface is used to get the range of valid values for the field passes as a parameter. This method returns the ValueRange object which contains the minimum and maximum valid values for a field. This ChronoZonedDateTime 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.
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. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
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:
ChronoZonedDateTime of Calcutta: 2018-12-06T19:21:12.123+05:30[Asia/Calcutta] Range of MILLI_OF_SECOND: 0 - 999
ChronoZonedDateTime of Calcutta: 2018-10-25T23:12:31.123+02:00[Europe/Paris] Range of NANO_OF_SECOND: 0 - 999999999