Question: I'm trying to convert an input date string to a date format and then to a datetime format.
As a test, I gave an input of an incorrect date format, but this doesn't seem to be throwing any parse exceptions and gives me the wrong output. Any thoughts on what my code below is doing wrong?

```
            String OLD_FORMAT ="MM/dd/yyyy";
            String NEW_FORMAT ="yyyyMMdd HHmmss";
            SimpleDateFormat sdf = new SimpleDateFormat(OLD_FORMAT);
            String oldDateString = "03/01211/2012"; //Incorrect input
            Date myOldDate;
            Datetime myNewDate;
            try {
                myOldoldDate = sdf.parse(oldDateString); 
           //Returns Wed Jun 24 00:00:00 IST 2015...why?? 
          //Shouldn't this be throwing a parse exception?
            } catch (ParseException e) {
                logger.error("Error while parsing Date");
            }
            sdf.applyPattern(NEW_FORMAT);
            //Converting date to datetime format
            try {
                myNewDate= DateHelper.toDatetime(sdf.parse((sdf.format(myOldDate)))); 
           //Returns 2015-06-24 00:00:00.0
            } catch (ParseException e) {
                logger.error("Error while parsing Date");
            }

```

Answer: 
"03/01211/2012" => Jun 24 00:00:00 IST 2015 ... why?

My guess is that June 24th, 2015 is 1211 days from March 1st, 2012.
Excessive rollover, reads it as March 1211th.

You should be able to turn this off with:

```
sdf.setLenient(false)

```

> 
> public void setLenient(boolean lenient)
> 
> 
> Specify 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 interpretation, such dates will cause an exception to be thrown. 
> 
> 
>
You can set strict format

[SimpleDateFormat.setLenient(false)](http://docs.oracle.com/javase/1.4.2/docs/api/java/text/DateFormat.html#setLenient%28boolean%29)

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.