OffsetDateTime range() method in Java with Examples Last Updated : 28 Jan, 2019 Comments Improve Suggest changes Like Article Like Report 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 // 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); } } Output: Range in CLOCK_HOUR_OF_AMPM: 1 - 12 Program 2: Java // 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); } } Output: Range in SECOND_OF_DAY: 0 - 86399 References: https://docs.oracle.com/javase/10/docs/api/java/time/OffsetDateTime.html#range(java.time.temporal.TemporalField) Comment More infoAdvertise with us Next Article OffsetDateTime range() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions Java-time package Java-OffsetDateTime Practice Tags : Java Similar Reads OffsetTime range() method in Java with Examples range() method of the OffsetTime class used to get the range in terms of the minimum and maximum values for the field passed as a parameter to this method. The returned value for this method is ValueRange object for the field and the method returns ValueRange object only for those fields which are s 2 min read OffsetDateTime until() Method in Java with Examples until() method of the OffsetDateTime class used to calculate the amount of time between two OffsetDateTime objects using TemporalUnit. The start and end points are this and the specified OffsetDateTime passed as a parameter. The result will be negative if the end is before the start. The calculation 2 min read OffsetDateTime query() method in Java with Examples query() method of an OffsetDateTime class used to query this OffsetDateTime using the specified query as parameter.The TemporalQuery object passed as parameter define the logic to be used to obtain the result from this OffsetDateTime. Syntax: public <R> R query(TemporalQuery<R> query) Pa 2 min read OffsetDateTime of() method in Java with Examples The of(int year, int month, int day, int hour, int minute, int second, int nanosecond, ZoneOffset offset) method of the OffsetDateTime class in Java is used to create an instance of OffsetDateTime from the passed values of year, month, day, hour, minute, second, nanosecond and offset. In this method 3 min read OffsetDateTime with() Method in Java with Examples In OffsetDateTime class, there are two types of with() method depending upon the parameters passed to it. with(TemporalAdjuster adjuster) with(TemporalAdjuster adjuster) method of the OffsetDateTime class used to adjusted this OffsetDateTime using TemporalAdjuster and after adjustment returns the co 3 min read Like