I am trying to implement a method which parses String
to Date
, and I would like to use SimpleDateFormat
because that seems to do the work:
java.util.Date parseMonth(String str) throws ParseException {
SimpleDateFormat format=new SimpleDateFormat("MM/yyyy");
return format.parse(str);
}
But for some reasons, I get no ParseException
on inputs where I expect to get one.
- "00/2000" -> 1999-12-01, no Exception
- "13/2000" -> 2001-01-01, no Exception
What is the preferred way to check if a String
is a correct date (in respect to some implementation depended format)?