.isLenient()
THE-Spellchecker154 total contributions
Published Sep 10, 2023Updated May 15, 2024
Contribute to Docs
The .isLenient()
method of the Calendar
class returns True
if the interpretation of this Calendar
is lenient else it returns False
.
Syntax
calendar.isLenient()
Note: When a
Calendar
is lenient, it allows date and time values that may not make sense in a real-world context. For example,February 30th
or a time value of25:70:90
would be accepted. When aCalendar
is non-lenient, it enforces stricter rules, and attempting to set invalid date or time values will throw exceptions, such asIllegalArgumentException
.
Example 1
The example below demonstrates the use of the .isLenient()
method.
import java.util.Calendar;public class CalendarIsLenientExample {public static void main(String args[]){// Creating a calendar objectCalendar cal = Calendar.getInstance();// Displaying the calendarSystem.out.println("Current Calendar: " + cal.getTime());// Checking the leniencyboolean leniency = cal.isLenient();// Displaying the leniencySystem.out.println("Calendar is" + " lenient: " + leniency);}}
This code will return an output similar to the following:
Current Calendar: Wed Sep 06 17:51:57 GMT 2023Calendar is lenient: true
Example 2
The example below demonstrates the use of the .isLenient()
method.
import java.util.Calendar;public class CalendarIsLenientExample{public static void main(String args[]){// Creating a calendar objectCalendar cal = Calendar.getInstance();// Displaying the calendarSystem.out.println("Current Calendar: " + cal.getTime());// Checking the leniencyboolean leniency = cal.isLenient();cal.setLenient(false);leniency = cal.isLenient();// Displaying the leniencySystem.out.println("Calendar is" + " lenient: " + leniency);}}
This code will return an output similar to the following:
Current Calendar: Wed Sep 06 17:57:00 GMT 2023Calendar is lenient: false
All contributors
- THE-Spellchecker154 total contributions
- Atreay6 total contributions
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.