date puzzler explained

As someone pointed out the unexpected behavior really is coming from the parse method. Looking in the JavaDocs the behavior is likely coming from the DateFormat class:

By default, parsing is lenient: If the input is not in the form used by this object’s format method but can still be parsed as a date, then the parse succeeds. Clients may insist on strict adherence to the format by calling setLenient(false).

Although this isn’t specific, it may mean it will interpolate dates when the range falls outside of the correct value. Perhaps there is more detailed documentation, but this is all I found without being overly exhaustive about it. So beware if you are expecting parse() to perform strict date format checking for you. I have also found DateValidator() in Commons Validator to be useful in examining date formats.

Explore posts in the same categories: Java

Leave a comment