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








OffsetDateTime until(Temporal endExclusive, TemporalUnit unit) calculates the amount of time until another date-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.OffsetDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
/* w  w  w  .  ja v  a2s.co m*/
public class Main {
  public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.now();
    long d =  o.until(OffsetDateTime.now(ZoneId.systemDefault()),ChronoUnit.WEEKS);
    System.out.println(d);
  }
}

The code above generates the following result.