Wednesday, 4 April 2018

How to use dividedBy and multipliedBy methods of Duration class | Java 8 Date and Time


Click here to watch on Youtube: 
https://www.youtube.com/watch?v=CvxBKWfqv5g&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("Before dividedBy = " + duration);

        /*
         * Parameters:
         *
         * divisor - the value to divide the duration by, positive or
         * negative, not zero
         *
         * Returns:
         *
         * a Duration based on this duration divided by the specified
         * divisor, not null
         * /

        duration = duration.dividedBy(2);

        System.out.println("After dividedBy 2 = " + duration);

        duration = duration.multipliedBy(3);

        System.out.println("After multipliedBy 3 = " + duration);

    }

}

Output

Before dividedBy = PT12H
After dividedBy 2 = PT6H
After multipliedBy 3 = PT18H

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

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/c7899e666996cf29a48ef15f0030404863025004/BasicJava_2018/DurationDemo_divide_multiply/?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