DateFormat setLenient() Method in Java with Examples Last Updated : 01 Apr, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 DateFormat object. 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 setLenient() Method of Calendar class: Example 1: Java // Java code to illustrate // setLenient() method import java.text.*; import java.util.*; public class DateFormat_Demo { public static void main(String[] args) { // Initializing the first formatter DateFormat DFormat = DateFormat.getDateTimeInstance(); System.out.println("Object: " + DFormat); // String formatting String str = DFormat.format(new Date()); // Displaying the string time System.out.println(str); System.out.println("Leniency: " + DFormat.isLenient()); // Changing the leniency DFormat.setLenient(false); // Displaying the modified leniency System.out.println("New Leniency: " + DFormat.isLenient()); } } Output: Object: java.text.SimpleDateFormat@7945516e Mar 28, 2019 6:03:48 PM Leniency: true New Leniency: false Example 2: Java // Java code to illustrate // setLenient() method import java.text.*; import java.util.*; public class DateFormat_Demo { public static void main(String[] args) { // Initializing the first formatter DateFormat DFormat = DateFormat.getDateInstance(); System.out.println("Object: " + DFormat); // String formatting String str = DFormat.format(new Date()); // Displaying the string time System.out.println(str); System.out.println("Leniency: " + DFormat.isLenient()); // Changing the leniency DFormat.setLenient(false); // Displaying the modified leniency System.out.println("New Leniency: " + DFormat.isLenient()); } } Output: Object: java.text.SimpleDateFormat@ce9bf0a5 Mar 28, 2019 Leniency: true New Leniency: false Reference: https://docs.oracle.com/javase/7/docs/api/java/text/DateFormat.html#setLenient(boolean) Comment More infoAdvertise with us Next Article Date toString() method in Java with Examples C chinmoy lenka Follow Improve Article Tags : Misc Java Java-Functions Java-text package Java-DateFormat +1 More Practice Tags : JavaMisc Similar Reads DateFormat setCalendar() Method in Java with Examples The setCalendar() Method of DateFormat class in Java is used to set the calendar associated with this date/time format object. In the initial stage the default settings of calendar is used along with the default locale. Syntax: public void setCalendar(Calendar new_calendar) Parameter: The method tak 2 min read DateFormat setTimeZone() Method in Java with Examples The setTimeZone() method in DateFormat class is used to set the time-zone of the calendar of this DateFormat. Syntax: public void setTimeZone(TimeZone time_zone) Parameters: The method takes one parameter time_zone of TimeZone type and refers to the new time zone. Return Value: The method does not r 2 min read 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 th 2 min read Date setTime() method in Java with Examples The setTime() method of Java Date class sets a date object. It sets date object to represent time milliseconds after January 1, 1970 00:00:00 GMT. Syntax: public void setTime(long time) Parameters: The function accepts a single parameter time which specifies the number of milliseconds. Return Value: 2 min read Date toString() method in Java with Examples The toString() method of Java Date class converts this date object into a String in form "dow mon dd hh:mm:ss zzz yyy". This method overrides toString in class object. Syntax: public String toString() Parameters: The function does not accept any parameter. Return Value: It method returns a string re 2 min read Date toInstant() Method in Java with Examples The toInstant() method of Date class in Java is used to convert a Date object to an Instant object. An Instant is created during the conversion which is used to represent the same point on the timeline as this Date. Syntax: public Instant toInstant() Parameters: The method does not take any paramete 2 min read Like