Calendar類中的isLenient()方法用於了解和理解此Calendar的日期和時間解釋是否應被視為寬鬆的。
用法:
public boolean isLenient()
參數:該方法不帶任何參數。
返回值:如果此Calendar的解釋寬鬆,則該方法或者返回True,否則返回False。
以下示例程序旨在說明Calendar類的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("Calendat is"
+ " lenient: "
+ leniency);
}
}
輸出:
Current Calendar: Wed Feb 20 17:25:12 UTC 2019 Calendat 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("Calendat is"
+ " lenient: "
+ leniency);
}
}
輸出:
Current Calendar: Wed Feb 20 17:25:14 UTC 2019 Calendat is lenient: false
參考: https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html#isLenient-
相關用法
- Java DateFormat isLenient()用法及代碼示例
- Java Calendar add()用法及代碼示例
- Java Calendar set()用法及代碼示例
- Java Calendar get()用法及代碼示例
- Java Calendar setTimeInMillis()用法及代碼示例
- Java Calendar getInstance()用法及代碼示例
- Java Calendar hashCode()用法及代碼示例
- Java Calendar getTimeInMillis()用法及代碼示例
- Java Calendar getActualMaximum()用法及代碼示例
- Java Calendar isSet()用法及代碼示例
- Java Calendar roll()用法及代碼示例
- Java Calendar getActualMinimum()用法及代碼示例
- Java Calendar getTime()用法及代碼示例
- Java Calendar internalGet()用法及代碼示例
- Java Calendar setTime()用法及代碼示例
注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 Calendar isLenient() Method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。