OffsetDateTime until() Method in Java with Examples Last Updated : 22 Jan, 2019 Comments Improve Suggest changes Like Article Like Report 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 returns a whole number, representing the number of complete units between the two OffsetDateTime. This instance is immutable and unaffected by this method call. Syntax: public long until(Temporal endExclusive, TemporalUnit unit) Parameters: This method accepts two parameters endExclusive which is the end date, exclusive, which is converted to an OffsetDateTime and unit which is the unit to measure the amount. Return value: This method returns the amount of time between this OffsetDateTime and the end OffsetDateTime. Exception:This method throws following Exceptions: DateTimeException – if the amount cannot be calculated, or the ending temporal cannot be converted to an OffsetDateTime. UnsupportedTemporalTypeException – if the unit is not supported. ArithmeticException – if numeric overflow occurs. Below programs illustrate the until() method: Program 1: Java // Java program to demonstrate // OffsetDateTime.until() method import java.time.*; import java.time.temporal.*; public class GFG { public static void main(String[] args) { // create OffsetDateTime objects OffsetDateTime date1 = OffsetDateTime.parse("2018-12-12T13:30:30+05:00"); OffsetDateTime date2 = OffsetDateTime.parse("2015-12-12T13:30:30+05:00"); // apply until method of OffsetDateTime class long result = date2.until(date1, ChronoUnit.MONTHS); // print results System.out.println("Result in MONTHS: " + result); } } Output: Result in MONTHS: 36 Program 2: Java // Java program to demonstrate // OffsetDateTime.until() method import java.time.*; import java.time.temporal.*; public class GFG { public static void main(String[] args) { // create OffsetDateTime objects OffsetDateTime date1 = OffsetDateTime.parse("2018-12-12T13:30:30+05:00"); OffsetDateTime date2 = OffsetDateTime.parse("2015-12-12T13:30:30+05:00"); // apply until method of OffsetDateTime class long result = date1.until(date2, ChronoUnit.YEARS); // print results System.out.println("Result in YEARS: " + result); } } Output: Result in YEARS: -3 References: https://docs.oracle.com/javase/10/docs/api/java/time/OffsetDateTime.html#until(java.time.temporal.Temporal, java.time.temporal.TemporalUnit) Comment More infoAdvertise with us Next Article OffsetDateTime until() 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 until() Method in Java with Examples until() method of the OffsetTime class used to calculate the amount of time between two OffsetTime objects using TemporalUnit. The start and end points are this and the specified OffsetTime passed as a parameter. The result will be negative if the end is before the start. The calculation returns a w 2 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 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 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 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 plusMonths() method in Java with examples The plusMonths() method of OffsetDateTime class in Java returns a copy of this OffsetDateTime with the specified number of months added to the parsed date and time. Syntax: public OffsetDateTime plusMonths(long months) Parameter: This method accepts a single parameter months which specifies the mont 2 min read OffsetDateTime plusMinutes() method in Java with examples The plusMinutes() method of OffsetDateTime class in Java returns a copy of this OffsetDateTime with the specified number of minutes added to the parsed date and time. Syntax: public OffsetDateTime plusMinutes(long minutes) Parameter: This method accepts a single parameter minutes which specifies the 2 min read OffsetDateTime plusNanos() method in Java with examples The plusNanos() method of OffsetDateTime class in Java returns a copy of this OffsetDateTime with the specified number of nanoseconds added to the parsed date and time. Syntax: public OffsetDateTime plusNanos(long nanoseconds) Parameter: This method accepts a single parameter nanoseconds which speci 2 min read OffsetDateTime get() method in Java with examples The get() method of OffsetDateTime class in Java gets the value of the specified field from this date as an int. Syntax : public int get(TemporalField field) Parameter : This method accepts a single parameter field which specifies the field to get, not null.Return Value: It returns the value for the 2 min read OffsetDateTime plusDays() method in Java with examples The plusDays() method of OffsetDateTime class in Java returns a copy of this OffsetDateTime with the specified number of days added to the parsed date and time. Syntax: public OffsetDateTime plusDays(long days) Parameter: This method accepts a single parameter days which specifies the days to be add 2 min read Like