What is the use of “lenient “?

The javadoc clearly states:

Specify whether or not date/time parsing is to be lenient. With
lenient parsing, the parser may use heuristics to interpret inputs
that do not precisely match this object’s format. With strict parsing,
inputs must match this object’s format.

So, if you have a pattern and create a date object that strictly matches your pattern, set lenient to false. Also, DateFormat is lenient, by default.

Basically, DateFormat sets Calendar.setLenient and the Javadoc states:

Specifies whether or not date/time interpretation is to be lenient.
With lenient interpretation, a date such as “February 942, 1996” will
be treated as being equivalent to the 941st day after February 1,
1996. With strict (non-lenient) interpretation, such dates will cause
an exception to be thrown. The default is lenient.

Leave a Comment