开发者

SimpleDateFormat not catching invalid 13th month

I am attempting to validate a query parameter for a date. If an invalid date is entered i return an 400 BAD_REQUEST response code. However, my validation is not catching an invalid date of '201113'. It does however, catch an invalid year such as '000012'. I am using the following code:

SimpleDateFormat df = new SimpleDateFormat("yyyymm"); 
    df.setLenient(false);
    try
    {
        df.parse(endDate);
        df.parse(startDate);
    }
    catch(ParseException e)
    {
        throw new WebApplicationException(Response.Status.BAD_REQUEST);
    }

I know that setting lenient to false sho开发者_如何学Gould have fixed this problem, but it persists. Thanks for your time.


"mm" is for minutes. "MM" is for months... Try "yyyyMM" as your format string instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜