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 教师闺蜜祝福语简短