Java中的MonthDay isSupported()方法
可以使用isSupported()Java中MonthDay类中的方法来检查MonthDay类是否支持ChronoField。此方法需要单个参数,即ChronoField进行检查。如果MonthDay类支持ChronoField,则返回true,否则返回false。
演示此程序如下
示例
import java.time.*;
import java.time.temporal.*;
public class Demo {
public static void main(String[] args) {
MonthDay md = MonthDay.now();
System.out.println("The MonthDay is: " + md);
boolean flag = md.isSupported(ChronoField.MONTH_OF_YEAR);
if(flag)
System.out.println("The ChronoField MONTH_OF_YEAR is supported");
else
System.out.println("The ChronoField MONTH_OF_YEAR is not supported");
}
}输出
The MonthDay is: --02-21 The ChronoField MONTH_OF_YEAR is supported
现在让我们了解上面的程序。
首先,显示当前的MonthDay对象。然后,该isSupported()方法用于检查MonthDay类是否支持ChronoFieldMONTH_OF_YEAR。返回的值存储在标志中,并打印相应的响应。演示此代码段如下所示:
MonthDay md = MonthDay.now();
System.out.println("The MonthDay is: " + md);
boolean flag = md.isSupported(ChronoField.MONTH_OF_YEAR);
if(flag)
System.out.println("The ChronoField MONTH_OF_YEAR is supported");
else
System.out.println("The ChronoField MONTH_OF_YEAR is not supported");热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短