Monday, 16 April 2018

How to use isNegative and isZero methods of Duration class | Java 8 Date and Time


Click here to watch on Youtube:
https://www.youtube.com/watch?v=qUyoIW4WezI&list=UUhwKlOVR041tngjerWxVccw

DurationDemo.java

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

public class DurationDemo
{
    public static void main(String[] args)
    {

        Duration duration = Duration.between(LocalTime.NOON,
                LocalTime.MIDNIGHT);
        System.out.println("duration = "+duration);
        /*
         * Returns:true if this duration has a total length less than
         * zero
         */

        System.out.println("is duration Negative? = "+duration.isNegative());

        /*
         * Returns:true if this duration has a total length equal to
         * zero
         */

        System.out.println("is duration zero? = "+duration.isZero());
    }

}

Output

duration = PT-12H
is duration Negative? = true
is duration zero? = false

Click the below link to download the code:
https://sites.google.com/site/ramj2eev2/java_basics/DurationDemo_isNegative_zero.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava_2018/DurationDemo_isNegative_zero

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/8497cbe1b661ade036f769d804f96b3ba18763d5/BasicJava_2018/DurationDemo_isNegative_zero/?at=master

See also:

  • All JavaEE Videos Playlist
  • All JavaEE Videos
  • All JAVA EE Links
  • Spring Tutorial
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • Cooking Tutorial
  • No comments:

    Post a Comment