Java Date Time - Java Calendar.setLenient(boolean lenient)








Syntax

Calendar.setLenient(boolean lenient) has the following syntax.

public void setLenient(boolean lenient)

Example

In the following code shows how to use Calendar.setLenient(boolean lenient) method.

import java.util.Calendar;
/*  www .j a v  a  2 s. c  om*/
public class Main {

   public static void main(String[] args) {
      Calendar cal = Calendar.getInstance();

      // print current state of lenient
      boolean b = cal.isLenient();
      System.out.println("Calendar is lenient :" + b);

      // change lenient state
      cal.setLenient(false);

      System.out.println("Lenient after setting :" + cal.isLenient());

   }
}

The code above generates the following result.