I was trying to answer a question, and I prepared a little example, expecting to offer some success and error messages, after having the code working I tried:
CODE
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
// correct format in string but totally wrong data for a date.
String curDate = "2015-18-32";
Date parsedDate = null;
try {
parsedDate = format.parse(curDate);
} catch (ParseException e) {}
System.out.println(parsedDate);
OUTPUT
Sat Jul 02 00:00:00 CEST 2016
I understand resulting date is just the valid one (2015-12-31) adding 6 months and 1 day to the date, but that does not seem correct for me. Am I misunderstanding SimpleDateFormat
?
- Shouldn't this code give an exception or error?