Calendar setLenient() Method in Java with Examples

The setLenient(boolean leniency) method in Calendar class is used to specify whether the interpretation of the date and time is to be lenient or not.

Syntax:

public void setLenient(boolean leniency)

Parameters: The method takes one parameter leniency of the boolean type that refers to the mode of the calendar. The boolean value true turns on the leniency mode and false turns off the leniency mode.

Return Value: The method does not return any value.

Below programs illustrate the working of setFirstDayOfWeek() Method of Calendar class:
Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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());
    }
}

chevron_right


Output:

Is the Calendar lenient? true
The altered Leniency: false

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
    }
}

chevron_right


Output:

Current Calendar: Thu Feb 21 11:00:50 UTC 2019
Calendar is lenient? false
Calendar is lenient: true

Reference: https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html#setLenient-boolean-



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.