Java中的 Calendar isLenient() 方法及示例
Calendar 类中的isLenient()方法用于了解和理解该 Calendar 的日期和时间解释是否被认为是宽松的。
句法:
public boolean isLenient()
参数:该方法不带任何参数。
返回值:如果此 Calendar 的解释是宽松的,则该方法要么返回True ,否则返回False 。
下面的程序说明了 Calendar 类的 isLenient() 方法的工作原理:
示例 1:
Java
// 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);
}
}
Java
// 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:25:50 UTC 2021
Calendar is lenient: true
示例 2:
Java
// 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: Java/util/Calendar.html#isLenient–