當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java Calendar isLenient()用法及代碼示例


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-



相關用法


注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 Calendar isLenient() Method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。