[thelist] [Java] Date validation
Hassan Schroeder
hassan at webtuitive.com
Wed Jan 16 18:33:34 CST 2002
Howard Cheng wrote:
> 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.
> 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);
/* add the following line */
gcDate.getTime();
> } catch (Exception e) {
> return false;
> }
> return true;
> }
> But my function always returns true. Any ideas?
<excerpt src="Java 1.3 Calendar class page">
Calendar fields can be changed using three methods: set(), add(),
and roll().
set(f, value) changes field f to value. In addition, it sets an
internal member variable to indicate that field f has been changed.
Although field f is changed immediately, the calendar's milliseconds
is not recomputed until the next call to get(), getTime(), or
getTimeInMillis() is made.
</excerpt>
HTH!
--
H*
Hassan Schroeder ----------------------------- hassan at webtuitive.com
Webtuitive Design === (+1) 408-938-0567 === http://webtuitive.com
-- creating dynamic Web sites and applications since 1994 --
More information about the thelist
mailing list