[thelist] [Java] Date validation
Howard Cheng
howcheng at ix.netcom.com
Wed Jan 16 17:21:32 CST 2002
Hello all,
I'm trying to do some date validation in Java (JSP) and it's just not doing
what the manual says it should do, so perhaps someone here has an answer.
Here's the code:
public boolean CheckDate(int month, int day, int year)
{ java.util.GregorianCalendar gcDate = new java.util.GregorianCalendar();
gcDate.clear();
gcDate.setLenient(false);
try {
gcDate.set(year, month, day);
} catch (Exception e) {
return false;
}
return true;
}
According to the Java(tm) 2 Platform Std Ed v1.3.1 doc...
<excerpt>
When a Calendar is lenient, it accepts a wider range of field values than
it produces. For example, a lenient GregorianCalendar interprets MONTH ==
JANUARY, DAY_OF_MONTH == 32 as February 1. A non-lenient GregorianCalendar
throws an exception when given out-of-range field settings. When calendars
recompute field values for return by get(), they normalize them. For
example, a GregorianCalendar always produces DAY_OF_MONTH values between 1
and the length of the month.
</excerpt>
But my function always returns true. Any ideas?
Thanks.
::::::::::::::::::::::
Howard Cheng
howcheng at ix.netcom.com
AIM: bennyphoebe
ICQ: 47319315
More information about the thelist
mailing list