OffsetDateTime until(Temporal endExclusive, TemporalUnit unit) example
Description
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;
/*from w w w . j a v a2s . c o 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.