Java: How to parse a date strictly?

date, java, parsing, validation

Solution

`fmt.setLenient(false);` is what you're looking for.

Problem

SimpleDateFormat is a very kind parser that rolls the resulting date instead of throwing an error. How can I parse a date strictly without regexps etc? ``` fmt = new SimpleDateFormat("dd.MM.yyyy") fmt.parse("10.11.2012") // it works fmt.parse("10.1150.2012") // it works but it's unwanted ```

Original source

Related problems