Thursday 29 March 2018

How to use normalized method of Period Class | Java 8 Date and Time


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

PeriodDemo.java

import java.time.Period;

public class PeriodDemo
{

    public static void main(String[] args)
    {

        Period period1 = Period.ofMonths(14);
        System.out.println("period1 = " + period1);

        /*
         * Ret urns a copy of this period with the years and months
         * normalized.
         *
         * Returns:
         *
         * a Period based on this period with excess months normalized
         * to years, not null
         */

        Period period2 = period1.normalized();
        System.out.println("period2 = " + period2);

    }

}

Output

period1 = P14M
period2 = P1Y2M

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

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava_2018/PeriodDemo-normalized

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/755fea7aeca931764d09d2ae6d0900a44d7186bb/BasicJava_2018/PeriodDemo-normalized/?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