当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。