Java 日历 isLenient()方法及示例
Calendar类中的 isLenient() 方法用于了解和理解该日历的日期和时间解释是否被认为是宽松的。
语法
public boolean isLenient()
参数: 该方法不接受任何参数。
返回值: 如果这个日历的解释是宽松的,该方法返回 True ,否则返回 false
以下程序说明了日历类的isLenient()方法的工作:
例子1
// Java code to illustrate
// isLenient() method
import java.util.*;
public class CalendarDemo {
public static void main(String args[])
{
// Creating a calendar object
Calendar calndr = Calendar.getInstance();
// Displaying the calendar
System.out.println("Current Calendar: "
+ calndr.getTime());
// Checking the leniency
boolean leniency = calndr.isLenient();
// Displaying the leniency
System.out.println("Calendar is"
+ " lenient: "
+ leniency);
}
}
输出
Current Calendar: Tue Nov 30 10:25:50 UTC 2021
Calendar is lenient: true
例2 :
// Java code to illustrate
// isLenient() method
import java.util.*;
public class CalendarDemo {
public static void main(String args[])
{
// Creating a calendar object
Calendar calndr = Calendar.getInstance();
// Displaying the calendar
System.out.println("Current Calendar: "
+ calndr.getTime());
// Checking the leniency
boolean leniency = calndr.isLenient();
calndr.setLenient(false);
leniency = calndr.isLenient();
// Displaying the leniency
System.out.println("Calendar is"
+ " lenient: "
+ leniency);
}
}
输出
Current Calendar: Tue Nov 30 10:26:18 UTC 2021
Calendar is lenient: false
参考资料: https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html#isLenient-