Returns the amount of time between this instance and the provided 'endExclusive' date-time in terms of the specified unit.
package com.logicbig.example.zoneddatetime;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.time.temporal.UnsupportedTemporalTypeException;
public class UntilExample {
public static void main(String... args) {
ZonedDateTime d1 = ZonedDateTime.now();
ZonedDateTime d2 = d1.minusDays(500);
System.out.println(d1);
System.out.println(d2);
for (ChronoUnit chronoUnit : ChronoUnit.values()) {
try {
long l = d2.until(d1, chronoUnit);
System.out.printf("Until in unit %8s: %s%n", chronoUnit, l);
} catch (UnsupportedTemporalTypeException e) {
System.out.printf(" -- %s not supported%n", chronoUnit);
}
}
}
}
Output
2017-05-01T16:00:26.297-05:00[America/Chicago]
2015-12-18T16:00:26.297-06:00[America/Chicago]
Until in unit Nanos: 43196400000000000
Until in unit Micros: 43196400000000
Until in unit Millis: 43196400000
Until in unit Seconds: 43196400
Until in unit Minutes: 719940
Until in unit Hours: 11999
Until in unit HalfDays: 999
Until in unit Days: 500
Until in unit Weeks: 71
Until in unit Months: 16
Until in unit Years: 1
Until in unit Decades: 0
Until in unit Centuries: 0
Until in unit Millennia: 0
Until in unit Eras: 0
-- Forever not supported