ChronoLocalDate range() method in Java with Examples
The range() method of a ChronoLocalDate 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. When the field is not supported then an exception is thrown. This ChronoLocalDate is helpful to enhance the accuracy of the returned range.
Syntax:
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:
Program 1:
// Java program to demonstrate // ChronoLocalDate.range() method import java.time.*; import java.time.temporal.*; import java.time.chrono.*; public class GFG { public static void main(String[] args) { // create a ChronoLocalDate object ChronoLocalDate localD = LocalDate.parse("2018-12-06"); // print ChronoLocalDate System.out.println("ChronoLocalDate: " + localD); // get range of Days field // from ChronoLocalDate using range method ValueRange range = localD.range(ChronoField.DAY_OF_MONTH); // print range of DAY_OF_MONTH System.out.println("Range of DAY_OF_MONTH: " + range); } } |
ChronoLocalDate: 2018-12-06 Range of DAY_OF_MONTH: 1 - 31
Program 2:
// Java program to demonstrate // ChronoLocalDate.range() method import java.time.*; import java.time.temporal.*; import java.time.chrono.*; public class GFG { public static void main(String[] args) { // create a ChronoLocalDate object ChronoLocalDate localD = LocalDate.parse("2018-12-06"); // print ChronoLocalDate System.out.println("ChronoLocalDate: " + localD); // get range of DAY_OF_YEAR field // from ChronoLocalDate using range method ValueRange range = localD.range(ChronoField.DAY_OF_YEAR); // print range of DAY_OF_YEAR System.out.println("Range of DAY_OF_YEAR: " + range); } } |
ChronoLocalDate: 2018-12-06 Range of DAY_OF_YEAR: 1 - 365
Recommended Posts:
- ChronoLocalDate until(ChronoLocalDate) Method in Java with Examples
- ChronoLocalDate get() method in Java with Examples
- ChronoLocalDate from() method in Java with Examples
- ChronoLocalDate lengthOfMonth() method in Java with Examples
- ChronoLocalDate format() method in Java with Examples
- ChronoLocalDate compareTo() method in Java with Examples
- ChronoLocalDate getChronology() method in Java with Examples
- ChronoLocalDate hashCode() method in Java with Examples
- ChronoLocalDate plus(TemporalAmount) method in Java with Examples
- ChronoLocalDate toEpochDay() method in Java with Examples
- ChronoLocalDate isBefore() method in Java with Examples
- ChronoLocalDate isAfter() method in Java with Examples
- ChronoLocalDate adjustInto() method in Java with Examples
- ChronoLocalDate getEra() method in Java with Examples
- ChronoLocalDate lengthOfYear() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



