boolean isSet(int field)
描述 (Description)
java.util.Calendar.isSet(int field)方法检查给定的日历field是否具有值set.Cases表示该值已由get方法调用触发的内部字段计算设置。
声明 (Declaration)
以下是java.util.Calendar.isSet方法的声明
public final boolean isSet(int field)
参数 (Parameters)
field - 要检查的字段。
返回值 (Return Value)
如果给定的日历字段具有值集,则此方法返回true ; 否则是false 。
异常 (Exception)
NA
例子 (Example)
以下示例显示了java.util.calendar.isSet()方法的用法。
package com.iowiki;
import java.util.*;
public class CalendarDemo {
public static void main(String[] args) {
// create a calendar
Calendar cal = Calendar.getInstance();
// display the current calendar
System.out.println("Current Day is " + cal.get(Calendar.DAY_OF_MONTH));
// determine if the given calendar field has a value set
boolean b = cal.isSet(Calendar.DAY_OF_MONTH);
System.out.println("Day of month is set: " + b);
// clear day of month
cal.clear(Calendar.DAY_OF_MONTH);
// determine if the given calendar field has a value set
b = cal.isSet(Calendar.DAY_OF_MONTH);
System.out.println("Day of month is set: " + b);
}
}
让我们编译并运行上面的程序,这将产生以下结果 -
Current Day is 6
Day of month is set: true
Day of month is set: false