Friday, 2 February 2018

How to use isValidYear method of MonthDay Class | Java 8 Date and Time


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

MonthDayDemo.java

import java.time.MonthDay;

public class MonthDayDemo
{

    public static void main(String[] args)
    {
        MonthDay monthDay = MonthDay.parse("--02-29");
        System.out.println(monthDay);

        /*
         * Parameters:
         *
         * year - the year to validate
         *
         * Returns:
         *
         * true if the year is valid for this month-day
         */

        boolean isYearValid = monthDay.isValidYear(2000);
        System.out.println(
                "is --02-29 valid for the year 2000 ? = " + isYearValid);

        isYearValid = monthDay.isValidYear(2017);
        System.out.println(
                "is --02-29 valid for the year 2017 ? = " + isYearValid);

    }

}

Output

--02-29
is --02-29 valid for the year 2000 ? = true
is --02-29 valid for the year 2017 ? = false

Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/MonthDayDemo_isValidYear.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/MonthDayDemo_isValidYear

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/d57185a7bf9e23294d2a9e7b3cf655cc136de202/BasicJava/MonthDayDemo_isValidYear/?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
  • No comments:

    Post a Comment