Calendar.isLenient() To get status of Leninet of a Calendar.
Returns boolean: true or false , if the interpretation mode of this calendar is lenient then true otherwises false.
package my_proj;
import java.util.Calendar;
public class my_first {
public static void main(String[] args) {
Calendar my_cal = Calendar.getInstance();// created calendar
System.out.println(my_cal.isLenient()); // true
}
}
We can use setLenient() to change the interpretation mode .
package my_proj;
import java.util.Calendar;
public class my_first {
public static void main(String[] args) {
Calendar my_cal = Calendar.getInstance();// created calendar
System.out.println(my_cal.isLenient()); // true
my_cal.setLenient(false);
my_cal.set(2020,2,32);
System.out.println( my_cal.getTime());
}
}
Above code will generate exception. Change the code to my_cal.setLenient(true);
package my_proj;
import java.util.Calendar;
public class my_first {
public static void main(String[] args) {
Calendar my_cal = Calendar.getInstance();// created calendar
System.out.println(my_cal.isLenient()); // true
my_cal.setLenient(true);
my_cal.set(2020,2,32);
System.out.println( my_cal.getTime());
}
}