Close

Java Date Time - Duration.isZero() Examples

Java Date Time Java Java API 


Class:

java.time.Duration

java.lang.Objectjava.lang.Objectjava.time.Durationjava.time.Durationjava.time.temporal.TemporalAmountTemporalAmountjava.lang.ComparableComparablejava.io.SerializableSerializableLogicBig

Method:

public boolean isZero()

Checks if this duration is of zero length.

Examples


package com.logicbig.example.duration;

import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

public class IsZeroExample {

public static void main(String... args) {
Duration d = Duration.between(LocalDate.now().atStartOfDay(), LocalDateTime.now());
System.out.println(d);

boolean b = d.isZero();
System.out.println(b);

Duration d2 = Duration.between(LocalTime.now(), LocalDateTime.now());
boolean b2 = d2.isZero();
System.out.println(b2);
}
}

Output

PT15H59M20.349S
false
true




See Also