Java Date Time - Duration between(Temporal startInclusive, Temporal endExclusive) example








Duration between(Temporal startInclusive, Temporal endExclusive) gets a Duration representing the duration between two temporal objects.

Syntax

between has the following syntax.

public static Duration between(Temporal startInclusive,   Temporal endExclusive)

Example

The following example shows how to use between.

import java.time.Duration;
import java.time.LocalTime;
import java.time.temporal.ChronoUnit;
/*from ww  w .j  a va2s  .c  o  m*/
public class Main {
  public static void main(String[] args) {
    Duration duration = Duration.between(LocalTime.MIDNIGHT,LocalTime.NOON);
    System.out.println(duration.get(ChronoUnit.SECONDS));
    
  }
}

The code above generates the following result.