Duration isZero() example

Description

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;
/*ww  w.ja  v  a 2  s  .  c om*/
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.





















Home »
  Java Date Time »
    java.time Reference »




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