Thursday 29 March 2018

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


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

PeriodDemo.java

import java.time.Period;

public class PeriodDemo
{

    public static void main(String[] args)
    {

        Period period = Period.ofMonths(11);
        System.out.println("period = " + period);
        /*
         * Returns:
         *
         * the total number of months in the period, may be negative
         */

        long totalMonths = period.toTotalMonths();
        System.out.println("totalMonths = " + totalMonths);

    }

}

Output

period = P11M
totalMonths = 11

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

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

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