java.util.Calendar.isSet(int field) 方法檢查,如果給定日歷欄位的值集。例,該值被設定由一個get方法呼叫觸發內部欄位計算在內。
以下是java.util.Calendar.isSet方法的宣告
public final boolean isSet(int field)
field -- 進行檢查的欄位。
如果給定日歷欄位的值設定,此方法返回true; 否則為false。
NA
下面的範例演示java.util.calendar.isSet()方法的用法。
package com.yiibai; 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