Thursday 5 April 2018

How to use negated method of Duration class | Java 8 Date and Time


Click here to watch on Youtube: 
https://www.youtube.com/watch?v=8RoPoB2RDAg&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.MIDNIGHT,
                LocalTime.NOON);
        System.out.println("duration        = " + duration);

        /*
         * Returns:a Duration based on this duration with the amount
         * negated, not null
         */

        Duration negatedDuration = duration.negated();
        System.out.println("negatedDuration = " + negatedDuration);
    }

}

Output

duration        = PT12H
negatedDuration = PT-12H

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

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/cd3c99ca353758a9764fe433bd563318d1244d3f/BasicJava_2018/DurationDemo_negated/?at=master

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

    Post a Comment