Monday 26 March 2018

How to use length methods of YearMonth Class | Java 8 Date and Time


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

YearMonthDemo.java

import java.time.YearMonth;

public class YearMonthDemo
{

    public static void main(String[] args)
    {

        YearMonth yearMonth = YearMonth.now();
        System.out.println(yearMonth);

        /*
         * Returns:
         *
         * the length of the month in days, from 28 to 31
         */

        int lengthOfMonth = yearMonth.lengthOfMonth();
        System.out.println("lengthOfMonth = " + lengthOfMonth);

        /*
         * Returns:
         *
         * 366 if the year is leap, 365 otherwise
         */

        int lengthOfYear = yearMonth.lengthOfYear();
        System.out.println("lengthOfYear = " + lengthOfYear);
    }

}

Output

2018-03
lengthOfMonth = 31
lengthOfYear = 365

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

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

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