Search code examples
javadatesimpledateformatparseexception

SimpleDateFormat don't parse a string with a date when I use setLenient()


I don't understand what is going wrong with the code below:

SimpleDateFormat formatter = new SimpleDateFormat("MM.dd.yy hh:mm:ss");
formatter.setLenient(false);
formatter.parse("04.29.2017 00:55:05");

When I try to parse the string with a date I have a java.text.ParseException. What is wrong with my code?


Solution

  • hh expects a range of 1 through 12. Change it to HH (0 through 23) if you want it to work with lenient off.