OffsetDateTime range() method in Java with Examples
The range() method of the OffsetDateTime class used to get the ValueRange object which is the range of field in terms of the minimum and maximum values for the field passed as a parameter to this method. The method returns ValueRange object only for those fields which are supported by OffsetDateTime object. So when the field is not supported by this method then an exception is thrown by this method.
Syntax:
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:
Program 1:
// Java program to demonstrate // OffsetDateTime.range() method import java.time.*; import java.time.temporal.*; public class GFG { public static void main(String[] args) { // create OffsetDateTime objects OffsetDateTime offsetdateTime = OffsetDateTime .parse( "2018-12-12T13:30:30+05:00"); // apply range() method of OffsetDateTime class ValueRange result = offsetdateTime.range( ChronoField.CLOCK_HOUR_OF_AMPM); // print results System.out.println("Range in CLOCK_HOUR_OF_AMPM: " + result); } } |
Range in CLOCK_HOUR_OF_AMPM: 1 - 12
Program 2:
// Java program to demonstrate // OffsetDateTime.range() method import java.time.*; import java.time.temporal.*; public class GFG { public static void main(String[] args) { // create OffsetDateTime objects OffsetDateTime offsetdateTime = OffsetDateTime .parse( "2018-12-12T13:30:30+05:00"); // apply range() method of OffsetDateTime class ValueRange result = offsetdateTime.range( ChronoField.SECOND_OF_DAY); // print results System.out.println("Range in SECOND_OF_DAY: " + result); } } |
Range in SECOND_OF_DAY: 0 - 86399
Recommended Posts:
- OffsetDateTime from() method in Java with examples
- OffsetDateTime get() method in Java with examples
- OffsetDateTime until() Method in Java with Examples
- OffsetDateTime with() Method in Java with Examples
- OffsetDateTime minusMinutes() method in Java with examples
- OffsetDateTime plusDays() method in Java with examples
- OffsetDateTime minusYears() method in Java with examples
- OffsetDateTime minusSeconds() method in Java with examples
- OffsetDateTime plusMinutes() method in Java with examples
- OffsetDateTime withNano() method in Java with examples
- OffsetDateTime minusWeeks() method in Java with examples
- OffsetDateTime withHour() method in Java with examples
- OffsetDateTime plusMonths() method in Java with examples
- OffsetDateTime plusDays() method in Java with examples
- OffsetDateTime minusMonths() 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.



