这是我上一篇文章中的一个子问题,我没有得到答案。 如果String表示4月31日,6月等,则不抛出异常,但其他一切正常(例如4月32日或5月引发异常)。 我做错了什么?
public OrderDate(String date) throws IllegalDateFormatException
{
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/mm/yy");
try
{
dateFormat.setLenient(false);
dateFormat.parse(date);
this.date = date;
}
catch(ParseException e)
{
throw new IllegalDateFormatException("Date must have the following"
+ " format: dd/mm/yy");
}
}