Why this code doesn’t raise a ‘ParseException’ ?
DateFormat formatter = new SimpleDateFormat("dd/mm/yyyy");
try {
String date = "01/01/200'";
formatter.parse(date);
} catch (ParseException ex) {
throw new ParseException("Formato de fecha inválido",0);
}
Please explain that to me, I’m lost on that. And note the simple quote '
Because it’s what is supposed to do.
If you check the docs on DateFormat it says about the parameter.
source - A String whose beginning should be parsed.If you want to restrict the format, you’ll have to use regular expressions.
Also check the rules of SimpleDateformat about the year:
For parsing, if the number of pattern letters is more than 2, the year is interpreted literally, regardless of the number of digits. So using the pattern "MM/dd/yyyy", "01/11/12" parses to Jan 11, 12 A.D.