Java Calendar isLenient() 方法



描述

Java Calendar isLenient() 方法用於判斷日期和時間的解釋是否寬鬆。

宣告

以下是 java.util.Calendar.isLenient() 方法的宣告

public boolean isLenient()

引數

返回值

如果解釋模式為寬鬆,則返回 true;否則返回 false

異常

在當前日期日曆例項中檢查是否設定了 isLenient 示例

以下示例演示了 Java Calendar isLenient() 方法的使用。我們使用 getInstance() 方法建立當前日期的日曆例項,並使用 getTime() 方法列印日期和時間,以及使用 isLenient() 方法列印寬鬆設定。

package com.tutorialspoint;

import java.util.Calendar;

public class CalendarDemo {
   public static void main(String[] args) {
   
      // create a calendar    
      Calendar cal = Calendar.getInstance();

      // print the time
      System.out.println("Date And Time Is: " + cal.getTime());
	  
      // print the isLenient
      System.out.println("Interpretation Is lenient: " + cal.isLenient());
   }
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果:

Date And Time Is: Mon Sep 26 21:18:54 IST 2022
Interpretation Is lenient: true

在當前日期 GregorianCalendar 例項中檢查是否設定了 isLenient 示例

以下示例演示了 Java Calendar hashCode() 方法的使用。我們使用 GregorianCalendar() 方法建立當前日期的日曆例項,並使用 getTime() 方法列印日期和時間,以及使用 isLenient() 方法檢查寬鬆設定。

package com.tutorialspoint;

import java.util.Calendar;
import java.util.GregorianCalendar;

public class CalendarDemo {
   public static void main(String[] args) {
   
      // create a calendar    
      Calendar cal = new GregorianCalendar();

      // print the time
      System.out.println("Date And Time Is: " + cal.getTime());

      // print the isLenient
      System.out.println("Interpretation Is lenient: " + cal.isLenient());
   }
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果:

Date And Time Is: Mon Sep 26 21:19:40 IST 2022
Interpretation Is lenient: true

在給定日期 GregorianCalendar 例項中檢查是否設定了 isLenient 示例

以下示例演示了 Java Calendar hashCode() 方法的使用。我們使用 GregorianCalendar() 方法建立特定日期的日曆例項,並使用 getTime() 方法列印日期和時間,以及使用 isLenient() 方法檢查寬鬆設定。

package com.tutorialspoint;

import java.util.Calendar;
import java.util.GregorianCalendar;

public class CalendarDemo {
   public static void main(String[] args) {
   
      // create a calendar    
      Calendar cal = new GregorianCalendar(2025,8,26);

      // print the time
      System.out.println("Date And Time Is: " + cal.getTime());
	  
      // print the isLenient
      System.out.println("Interpretation Is lenient: " + cal.isLenient());
   }
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果:

Date And Time Is: Fri Sep 26 00:00:00 IST 2025
Interpretation Is lenient: true
java_util_calendar.htm
廣告