2月,4月,6月不会抛出DateFormatException

时间:2015-03-29 18:16:21

标签: java exception

这是我上一篇文章中的一个子问题,我没有得到答案。 如果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");
    }
}

0 个答案:

没有答案