Java: How to parse a date strictly? Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Java: How to parse a date strictly? without wasting too much if your time.

The question is published on by Tutorial Guruji team.

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


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

We are here to answer your question about Java: How to parse a date strictly? - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji