Calendar類中的setLenient(boolean leniency)方法用於指定日期和時間的解釋是否寬鬆。
用法:
public void setLenient(boolean leniency)
參數:該方法采用一種布爾類型的參數leniency,該leniency是指日曆的模式。布爾值true將打開寬大處理模式,而false則關閉寬大處理模式。
返回值:該方法不返回任何值。
以下示例程序旨在說明Calendar類的setFirstDayOfWeek()方法的用法:
示例1:
// Java code to illustrate
// setLenient() method
import java.util.*;
public class Calendar_Demo {
public static void main(String args[])
{
// Creating a calendar object
Calendar calndr = Calendar.getInstance();
// Displaying the current
// mood of leniency
boolean value = calndr.isLenient();
System.out.println("Is the"
+ " Calendar lenient? "
+ value);
// Changing the leniency
calndr.setLenient(false);
// Displaying the result
System.out.println("The altered"
+ " Leniency: "
+ calndr.isLenient());
}
}
輸出:
Is the Calendar lenient? true The altered Leniency: false
示例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);
// Checking the leniency
calndr.setLenient(true);
leniency = calndr.isLenient();
// Displaying the leniency
System.out.println("Calendar is"
+ " lenient: "
+ leniency);
}
}
輸出:
Current Calendar: Thu Feb 21 11:00:50 UTC 2019 Calendar is lenient? false Calendar is lenient: true
參考: https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html#setLenient-boolean-
相關用法
- Java DateFormat setLenient()用法及代碼示例
- Java Calendar set()用法及代碼示例
- Java Calendar get()用法及代碼示例
- Java Calendar add()用法及代碼示例
- Java Calendar getAvailableLocales()用法及代碼示例
- Java Calendar setFirstDayOfWeek()用法及代碼示例
- Java Calendar getDisplayName()用法及代碼示例
- Java Calendar getActualMaximum()用法及代碼示例
- Java Calendar roll()用法及代碼示例
- Java Calendar internalGet()用法及代碼示例
- Java Calendar getActualMinimum()用法及代碼示例
- Java Calendar getDisplayNames()用法及代碼示例
- Java Calendar getMinimum()用法及代碼示例
- Java Calendar getTime()用法及代碼示例
- Java Calendar hashCode()用法及代碼示例
注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 Calendar setLenient() Method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。