Open In App

Calendar setLenient() Method in Java with Examples

Last Updated : 21 Feb, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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:




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


Output:

Is the Calendar lenient? true
The altered Leniency: false

Example 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("Calendar is"
                           + " lenient? "
                           + leniency);
  
        // Checking the leniency
        calndr.setLenient(true);
        leniency = calndr.isLenient();
  
        // Displaying the leniency
        System.out.println("Calendar is"
                           + " lenient: "
                           + leniency);
    }
}


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-



Similar Reads

DateFormat setLenient() Method in Java with Examples
The setLenient(boolean leniency) method in DateFormat class is used to specify whether the interpretation of the date and time of this DateFormat object 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 of the Date
2 min read
Java Program to Generate Calendar of Any Year Without calendar.get() Function
Java program for generating the calendar of any desired year and month let us first go through an illustration before landing upon logic and procedural part. Illustration: Say the user wants to get the calendar of April 2011. Then, he is required to enter the year along with the month as integers and the output would return the desired month's cale
4 min read
Calendar clone() Method in Java with Examples
The clear() method in Calendar class is used to clone a calendar object. It basically creates a shallow copy of this object. Syntax: public Object clone() Parameters: The method does not take any parameters. Return Value: The method does not return any value. Below programs illustrate the working of clone() Method of Calendar class: Example 1: // J
2 min read
Calendar clear() Method in Java with Examples
The clear() method in Calendar class is used to set all the calendar field values and the time value of this Calendar undefined. Note: Implementation of calendar class may use default field values for date and time calculations. Syntax: public final void clear() Parameters: The method does not take any parameters. Return Value: The method does not
2 min read
Calendar add() Method in Java with Examples
The add() method of Calendar class present inside is used to add or subtract from the given calendar field(int field), a specific amount of time(int amt), based on the calendar's rules. Syntax: public abstract void add(int field, int amt) Parameters: The method takes two parameters: The field of the calendar on which the operation is to be performe
3 min read
Calendar toString() Method in Java with Examples
The toString() method in Calendar class is used to get the string representation of the Calendar object. This method in Calendar Class is just for debug process and not to be used as an operation. Syntax: public String toString() Parameters: The method does not take any parameters. Return Value: The method returns the String representation of the C
1 min read
Calendar compareTo() Method in Java with Examples
The add(Calendar Calendar2) method of Calendar class is used to compare the time values or the millisecond offsets of this Calendar object with the passed Calendar object. Syntax: public int compareTo(Calendar Calendar2) Parameters: The method takes one parameter Calendar2 of Calendar object type and refers to the object to be compared to this Cale
2 min read
Calendar complete() Method in Java with Examples
The complete() method in Calendar class is used to fill any unset fields of the calendar fields. It follows the following process of completion: At first, if the time value has not been calculated, the computeTime() method is called to calculate it from calendar field values. Second, to calculate all the calendar field values the computeFields() me
2 min read
Calendar computeTime() method in Java with Examples
The computeTime() method in Calendar class is used for the conversion operation of the current calendar field values in fields[] to the millisecond time value time. Syntax: protected abstract void computeTime() Parameters: The method does not take any parameters. Return Value: The method does not return any value. Below programs illustrate the work
2 min read
Calendar computeFields() method in Java with Examples
The computeFields() method in Calendar class is used for the conversion operation of the current millisecond time value time to calendar field values mentioned in the fields[]. Note: This allows syncing up the new time that is set for the calendar object with the calendar field values. Syntax: protected abstract void computeFields() Parameters: The
2 min read
Practice Tags :