Search code examples
javasimpledateformat

SimpleDateFormat giving wrong date instead of error


I am using following pattern and date

Date : 13-13-2007

Pattern : dd-MM-yyyy

Output: Sun Jan 13 00:00:00 IST 2008 Or 2008-01-13 00:00:00.0

I was expecting exception here. What can i do to generate exception when given date is inproper.


Solution

  • Use DateFormat.setLenient(false) to tell the DateFormat/SimpleDateFormat that you want it to be strict.