Java Date Time - LocalTime until(Temporal endExclusive, TemporalUnit unit) example








LocalTime until(Temporal endExclusive, TemporalUnit unit) calculates the amount of time until another time in terms of the specified unit.

Syntax

until has the following syntax.

public long until(Temporal endExclusive,  TemporalUnit unit)

Example

The following example shows how to use until.

import java.time.LocalTime;
import java.time.temporal.ChronoUnit;
//from   w w  w. ja v a2 s .  c om
public class Main {
  public static void main(String[] args) {
    LocalTime l = LocalTime.now();
    long s = l.until(LocalTime.NOON,ChronoUnit.HOURS);
    System.out.println(s);
  }
}

The code above generates the following result.