Click here to watch on Youtube:
https://www.youtube.com/watch?v=csKrtLhAkzA&list=UUhwKlOVR041tngjerWxVccw
YearDemo.java
Output
Click the below link to download the code:
https://sites.google.com/site/ramj2eev2/java_basics/YearDemo_isValidMonthDay.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava_2018/YearDemo_isValidMonthDay
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/8e3f14caa10b52912934997a22df069c728f47b4/BasicJava_2018/YearDemo_isValidMonthDay/?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
https://www.youtube.com/watch?v=csKrtLhAkzA&list=UUhwKlOVR041tngjerWxVccw
YearDemo.java
import java.time.Month;
import java.time.MonthDay;
import java.time.Year;
public class YearDemo
{
public static void main(String[] args)
{
Year year = Year.of(2017);
/*
* Parameters:
*
* monthDay - the month-day to validate, null returns false
*
* Returns:
*
* true if the month and day are valid for this year
*/
boolean isValidMonthDay = year
.isValidMonthDay(MonthDay.of(Month.FEBRUARY, 1));
System.out.println("isValidMonthDay = " + isValidMonthDay);
isValidMonthDay = year.isValidMonthDay(MonthDay.of(Month.FEBRUARY, 30));
System.out.println("isValidMonthDay = " + isValidMonthDay);
}
}
import java.time.MonthDay;
import java.time.Year;
public class YearDemo
{
public static void main(String[] args)
{
Year year = Year.of(2017);
/*
* Parameters:
*
* monthDay - the month-day to validate, null returns false
*
* Returns:
*
* true if the month and day are valid for this year
*/
boolean isValidMonthDay = year
.isValidMonthDay(MonthDay.of(Month.FEBRUARY, 1));
System.out.println("isValidMonthDay = " + isValidMonthDay);
isValidMonthDay = year.isValidMonthDay(MonthDay.of(Month.FEBRUARY, 30));
System.out.println("isValidMonthDay = " + isValidMonthDay);
}
}
Output
isValidMonthDay = true
Exception in thread "main" java.time.DateTimeException: Illegal value for DayOfMonth field, value 30 is not valid for month FEBRUARY
at java.time.MonthDay.of(Unknown Source)
at YearDemo.main(YearDemo.java:26)
Exception in thread "main" java.time.DateTimeException: Illegal value for DayOfMonth field, value 30 is not valid for month FEBRUARY
at java.time.MonthDay.of(Unknown Source)
at YearDemo.main(YearDemo.java:26)
Click the below link to download the code:
https://sites.google.com/site/ramj2eev2/java_basics/YearDemo_isValidMonthDay.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava_2018/YearDemo_isValidMonthDay
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/8e3f14caa10b52912934997a22df069c728f47b4/BasicJava_2018/YearDemo_isValidMonthDay/?at=master
See also:
No comments:
Post a Comment