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








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

The following units are supported.

  • NANOS
  • MICROS
  • MILLIS
  • SECONDS
  • MINUTES
  • HOURS
  • HALF_DAYS
  • DAYS
  • WEEKS
  • MONTHS
  • YEARS
  • DECADES
  • CENTURIES
  • MILLENNIA
  • ERAS




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.LocalDateTime;
import java.time.temporal.ChronoUnit;
//from   w ww . j ava2s  .  c  o  m
public class Main {
  public static void main(String[] args) {
    LocalDateTime a = LocalDateTime.of(2014, 6, 30, 12, 00);

    long l = a.until(LocalDateTime.now(),ChronoUnit.DAYS);
    
    System.out.println(l);
  }
}

The code above generates the following result.