Java中的MonthDay isValidYear()方法
可以使用isValidYear()Java中MonthDay类中的方法检查MonthDay对象的年份是否有效。此方法需要一个参数,即要检查的年份。另外,如果年份对于MonthDay对象有效,则返回true;如果年份对于MonthDay对象无效,则返回false。
演示此程序如下
示例
import java.time.*;
public class Demo {
public static void main(String[] args) {
MonthDay md = MonthDay.parse("--02-21");
System.out.println("The MonthDay is: " + md);
System.out.println("Year 2019 is valid for the MonthDay? " + md.isValidYear(2019));
}
}输出结果
The MonthDay is: --02-21 Year 2019 is valid for the MonthDay? true
现在让我们了解上面的程序。
首先,显示当前的MonthDay对象。然后使用该isValidYear()方法检查MonthDay对象的年份是否有效。返回值被打印。演示此的代码片段如下:
MonthDay md = MonthDay.parse("--02-21");
System.out.println("The MonthDay is: " + md);
System.out.println("Year 2019 is valid for the MonthDay? " + md.isValidYear(2019));热门推荐
10 简短他人的生日祝福语
11 回复生日祝福语 简短
12 感谢室友结婚祝福语简短
13 新娘生孩子祝福语简短
14 职场寄语老师祝福语简短
15 南宁招生老师祝福语简短
16 爸妈对宝宝祝福语简短
17 交个朋友蛋糕祝福语简短
18 情侣结婚的祝福语简短