Java Date Time - Duration isZero() example








Duration isZero() checks if this duration is zero length.

A Duration can be positive, zero or negative.

Syntax

isZero has the following syntax.

public boolean isZero()

Example

The following example shows how to use isZero.

import java.time.Duration;
import java.time.LocalTime;

public class Main {
  public static void main(String[] args) {
    Duration duration = Duration.between(LocalTime.MIDNIGHT,LocalTime.NOON);
    System.out.println(duration.isZero());
  }
}

The code above generates the following result.