Monday, 26 March 2018

How to use range method of YearMonth Class | Java 8 Date and Time


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

YearMonthDemo.java

import java.time.YearMonth;
import java.time.temporal.ChronoField;
import java.time.temporal.ValueRange;

public class YearMonthDemo
{

    public static void main(String[] args)
    {

        YearMonth yearMonth = YearMonth.now();

        /*
         * Parameters:
         *
         * field - the field to query the range for, not null
         *
         * Returns:
         *
         * the range of valid values for the field, not null
         */


        ValueRange yearRange = yearMonth.range(ChronoField.YEAR);
        System.out.println(yearRange);
        System.out.println("Min = " + yearRange.getMinimum());
        System.out.println("Max = " + yearRange.getMaximum());
       
        ValueRange monthRange = yearMonth.range(ChronoField.MONTH_OF_YEAR);
        System.out.println(monthRange);
        System.out.println("Min = " + monthRange.getMinimum());
        System.out.println("Max = " + monthRange.getMaximum());

    }

}

Output

-999999999 - 999999999
Min = -999999999
Max = 999999999
1 - 12
Min = 1
Max = 12

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

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

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