OffsetTime until() Method in Java with Examples Last Updated : 22 Jan, 2019 Comments Improve Suggest changes Like Article Like Report 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 whole number, representing the number of complete units between the two OffsetTime. 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 OffsetTime and unit which is the unit to measure the amount. Return value: This method returns the amount of time between this OffsetTime and the end OffsetTime. Exception:This method throws following Exceptions: DateTimeException – if the amount cannot be calculated, or the ending temporal cannot be converted to an OffsetTime. 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 // OffsetTime.until() method import java.time.*; import java.time.temporal.*; public class GFG { public static void main(String[] args) { // create OffsetTime objects OffsetTime o1 = OffsetTime.parse("03:30:30+05:00"); OffsetTime o2 = OffsetTime.parse("23:30:30+05:00"); // apply until method of OffsetTime class long result = o1.until(o2, ChronoUnit.MINUTES); // print results System.out.println("Result in MINUTES: " + result); } } Output: Result in MINUTES: 1200 Program 2: Java // Java program to demonstrate // OffsetTime.until() method import java.time.*; import java.time.temporal.*; public class GFG { public static void main(String[] args) { // create OffsetTime objects OffsetTime o1 = OffsetTime.parse("03:30:30+05:00"); OffsetTime o2 = OffsetTime.parse("19:30:30+05:00"); // apply until method of OffsetTime class long result = o1.until(o2, ChronoUnit.HOURS); // print results System.out.println("Result in HOURS: " + result); } } Output: Result in HOURS: 16 References: https://docs.oracle.com/javase/10/docs/api/java/time/OffsetTime.html#until(java.time.temporal.Temporal, java.time.temporal.TemporalUnit) Comment More infoAdvertise with us Next Article OffsetTime until() Method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions Java-time package Java-OffsetTime Practice Tags : Java Similar Reads 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 OffsetTime with() Method in Java with Examples In OffsetTime class, there are two types of with() method depending upon the parameters passed to it. with(TemporalAdjuster adjuster) with(TemporalAdjuster adjuster) method of the OffsetTime class used to adjusted this OffsetTime using TemporalAdjuster and after adjustment returns the copy of adjust 3 min read OffsetTime plus() method in Java with examples In OffsetTime class, there are two types of plus() method depending upon the parameters passed to it. plus(long amountToAdd, TemporalUnit unit) plus() method of a OffsetTime class used to return a copy of this OffsetTime with the specified amount of unit added.If it is not possible to add the amount 2 min read 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 OffsetTime query() method in Java with examples The Query() method of OffsetTime class in Java queries this time using the specified query. Syntax : public R query(TemporalQuery query) Parameter: This method accepts a single parameter query that specifies the query to be invoked and not null. Return Value: It returns the query result, null may be 1 min read Like