ZonedDateTime until(Temporal endExclusive, TemporalUnit unit) example

Description

ZonedDateTime 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.ZonedDateTime;
import java.time.temporal.ChronoUnit;
/* w  w  w .j ava  2 s  . co m*/
public class Main {
  public static void main(String[] args) {
    ZonedDateTime dateTime = ZonedDateTime.now();
    long o =  dateTime.until(ZonedDateTime.now(),ChronoUnit.YEARS);
    System.out.println(o);
  } 
}

The code above generates the following result.





















Home »
  Java Date Time »
    java.time Reference »




Clock
DayOfWeek
Duration
Instant
LocalDate
LocalDateTime
LocalTime
Month
MonthDay
OffsetDateTime
OffsetTime
Period
Year
YearMonth
ZonedDateTime
ZoneId
ZoneOffset