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 送给学长毕业祝福语简短