Monday 2 April 2018

How to create duration object using parse method of Duration class | Java 8 Date and Time


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

Click the below Image to Enlarge:


How to create duration object using parse method of Duration class | Java 8 Date and Time
DurationDemo.java

import java.time.Duration;

public class DurationDemo
{
    public static void main(String[] args)
    {
        /*
         * Parameters:
         *
         * text - the text to parse, not null
         *
         * Returns:
         *
         * the parsed duration, not null
         */

        Duration duration = Duration.parse("PT15M");
        System.out.println(duration);

        duration = Duration.parse("PT10H");
        System.out.println(duration);

        duration = Duration.parse("P2D");
        System.out.println(duration);

        duration = Duration.parse("P2DT3H4M");
        System.out.println(duration);

        duration = Duration.parse("P2DT3H4M");
        System.out.println(duration);

    }

}

Output

PT15M
PT10H
PT48H
PT51H4M
PT51H4M

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

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

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