java.util.Calendar isSet()方法

java.util.Calendar.isSet() 方法检查,如果给定日历字段的值集。例,该值被设置由一个get方法调用触发内部字段计算在内。

1 语法

public final boolean isSet(int field)

2 参数

field:进行检查的字段。

3 返回值

如果给定日历字段的值设置,此方法返回true; 否则为false。

4 示例1 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * java.util.Calendar isSet()方法的例子
 */
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

 

热门文章

优秀文章