Monday 2 April 2018

Java 8 Duration Class Introduction | Java 8 Date and Time | Java Date and Time


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

Click the below Image to Enlarge:
Java 8 Duration Class Introduction | Java 8 Date and Time | Java Date and Time
DurationDemo.java

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

public class DurationDemo
{

    public static void main(String[] args)
    {

        /*
         * Parameters:
         *
         * startInclusive - the start instant, inclusive, not null
         *
         * endExclusive - the end instant, exclusive, not null
         *
         * Returns: a Duration, not null
         *
         */

        Duration duration = Duration.between(LocalTime.MIDNIGHT,
                LocalTime.NOON);
        System.out.println("duration = " + duration);

        /*
         * Returns:the whole seconds part of the length of the
         * duration, positive or negative
         */

        System.out.println("seconds = " + duration.getSeconds());

        /*
         * Returns a copy of this duration with a positive length.
         */

        System.out.println("abs = " + duration.abs());

    }

}

Output

duration = PT12H
seconds = 43200
abs = PT12H

Refer: 
https://docs.oracle.com/javase/8/docs/api/index.html?java/time/Duration.html

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

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

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