Calendar类中的isSet(int calndr_field)方法用于检查给定日历字段是否设置了值。通过内部字段的计算为其设置值的所有Case均由get方法调用触发。
用法:
public final boolean isSet(int calndr_field)
参数:该方法采用一个参数calndr_field,该参数表示要操作的日历字段。
返回值:如果设置了日历字段的值,则该方法返回True,否则返回False。
以下示例程序旨在说明Calendar类的isSet()方法的用法:
示例1:
// Java code to illustrate
// isSet() method
import java.util.*;
public class CalendarDemo {
public static void main(String args[])
{
// Creating a calendar object
Calendar calndr = Calendar.getInstance();
// Displaying the calendar object
System.out.println("The Year is: "
+ calndr.get(Calendar.YEAR));
// Querying for the value if set or not
boolean val = calndr.isSet(Calendar.YEAR);
System.out.println("Is the"
+ " Value set? " + val);
// Clearing the instance
calndr.clear(Calendar.YEAR);
// Performing isSet() operation
val = calndr.isSet(Calendar.YEAR);
System.out.println("Is the"
+ " Value set? " + val);
}
}
输出:
The Year is: 2019 Is the Value set? true Is the Value set? false
示例2:
// Java code to illustrate
// isSet() method
import java.util.*;
public class CalendarDemo {
public static void main(String args[])
{
// Creating a calendar object
Calendar calndr = Calendar.getInstance();
// Displaying the calendar object
System.out.println("Todays Day is: "
+ calndr.get(
Calendar.DAY_OF_MONTH));
// Querying for the value if set or not
boolean val
= calndr.isSet(Calendar.DAY_OF_MONTH);
System.out.println("Is the"
+ " Value set? " + val);
// Clearing the instance
calndr.clear(Calendar.DAY_OF_MONTH);
// Performing isSet() operation
val = calndr.isSet(Calendar.DAY_OF_MONTH);
System.out.println("Is the"
+ " Value set? " + val);
}
}
输出:
Todays Day is: 21 Is the Value set? true Is the Value set? false
参考: https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html#isSet-int-
相关用法
- Java Calendar get()用法及代码示例
- Java Calendar set()用法及代码示例
- Java Calendar add()用法及代码示例
- Java Calendar setTime()用法及代码示例
- Java Calendar isLenient()用法及代码示例
- Java Calendar getActualMinimum()用法及代码示例
- Java Calendar getMaximum()用法及代码示例
- Java Calendar getActualMaximum()用法及代码示例
- Java Calendar compareTo()用法及代码示例
- Java Calendar getLeastMaximum()用法及代码示例
- Java Calendar getGreatestMinimum()用法及代码示例
- Java Calendar getMinimum()用法及代码示例
- Java Calendar getTimeInMillis()用法及代码示例
- Java Calendar getDisplayNames()用法及代码示例
- Java Calendar computeTime()用法及代码示例
注:本文由纯净天空筛选整理自Chinmoy Lenka大神的英文原创作品 Calendar isSet() Method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。