Hi Jeetandra!
 
I think U should use GregorianCalendar instead of Date.
 
Here is a source code:
 
 
GregorianCalendar g=new GregorianCalendar();
g.setLenient(false);
g.set(1999,01,29); 
System.out.println(g.get(GregorianCalendar.DATE)); 
 
As U see  the date is set to 1999 february 29 (wrong date).
 
This code throws IllegalArgumentException at runtime.
 
So u should check the date is if corect like this and if not send an error page
else U can format this date.  You can get a Date object calling g.getTime();
See the docs for GregorianCalendar for more info.
 
Don't forget g.setLenient(false).
 
p.s. If something is not right please fill free to contact me.
 
What about the Please wait window that U have asked last time ? Did U use my version ?
 
Best wishes,
                    Andras
 
 
 
 
 
 
-----Original Message-----
From: Jeetandra Mahtani <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Thursday, June 03, 1999 3:12 PM
Subject: converting to Julian Dates

>Hello,
>I have a form in which a user enters a date in the format mm/dd/yy.
>Now, the servlet that takes the input from this form, converts it to a Julian
>Date(yyyyMMdd) before storing it in a table.
>I have been doing this by the following:
>..
>SimpleDateFormat dat = new SimpleDateFormat("yyyyMMdd");
>
>String date1 = req.getParameterValues("indate")[0];
>Date date2 = new Date(date1);
>date1 = dat.format(date2);
>..
>and now date1 contains the format in yyyyMMdd. Fine, but if the user enters a date that is
>invalid like 02/32/99, it doesn't catch an exception but returns
>19990304.
>Is there any way by which I could catch an exception so that I could inform the user that
>the date is invalid.
>Thanks
>
>
>
>_________________________________________________________
>Do You Yahoo!?
>Get your free @yahoo.com address at http://mail.yahoo.com
>
>___________________________________________________________________________
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff SERVLET-INTEREST".
>
>Archives: http://archives.java.sun.com/archives/servlet-interest.html
>Resources: http://java.sun.com/products/servlet/external-resources.html
>LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to