Calendar.setLenient()
« Date
Calendar.setLenient(true / false ) To set status of Leninet of a Calendar.
package my_proj;
import java.util.Calendar;
public class my_first {
public static void main(String[] args) {
Calendar my_cal = Calendar.getInstance();// created calendar
my_cal.setLenient(true);
}
}
We can use getLenient() to collect 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
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
my_cal.setLenient(true);
my_cal.set(2020,2,32);
System.out.println( my_cal.isLenient()); //true
System.out.println( my_cal.getTime());
}
}
Output
true
Wed Apr 01 16:49:44 IST 2020
« getLeastMaximum() « getActualMaximum()
« Date & time tutorials
This article is written by plus2net.com team.
plus2net.com