Now change stringDate to

String stringDate = "02/01/1999";

Now what happens?  Oops, is that Jan 2, 1999 or is that Feb 1, 1999?  What
the original poster was asking for is effectively impossible. The date
format should be settable by the end user and shown on the input form so
that the user is responsible for entering the correct form. There isn't any
way that a program can do it correctly in all circumstances.

-----Original Message-----
From: Kishore Raghavan [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 21, 2000 6:51 PM
To: [EMAIL PROTECTED]
Subject: Re: How To Validate Date Format Using Java


Try this...

                String stringDate = "20/01/1999";

            try
            {
                SimpleDateFormat formatter = new SimpleDateFormat
("dd/MM/yyyy");
                ParsePosition pos = new ParsePosition(0);
                Date date = formatter.parse(stringDate, pos);
            }
            catch (Exception e)
            {
                        //Date is not valid
                        throw new IllegalArgumentException();
            }


Kishore


>From: "Arun M. Thomas" <[EMAIL PROTECTED]>
>Reply-To: A mailing list about Java Server Pages specification and
>     reference <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: Re: How To Validate Date Format Using Java
>Date: Wed, 21 Jun 2000 13:41:28 -0700
>
>This is just about impossible to do....
>
>Consider that there are valid dates where the month and day fields can
>be switched and still leave valid dates. For example:
>
>         mm/dd/yyyy - 01/09/1974 - Jan 9 1974
>         dd/mm/yyyy - 01/09/1974 - Sept 1 1974
>
>Both of these are valid dates, and there will be no way to distinguish
>between them.
>
>-AMT
>
> > -----Original Message-----
> > From: A mailing list about Java Server Pages specification and reference
> > [mailto:[EMAIL PROTECTED]]On Behalf Of tppal
> > Sent: Tuesday, June 20, 2000 9:28 PM
> > To: [EMAIL PROTECTED]
> > Subject: How To Validate Date Format Using Java
> >
> >
> > I need to validate this date format using format dd/mm/yyyy. If user
>input
> > other date format eg mm/dd/yyyy or yyyy-mm-dd, it's will automatically
> > convert to dd/mm/yyyy. How to do it?
> >
> > ==================================================================
> > =========
> > To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> > JSP-INTEREST".
> > Some relevant FAQs on JSP/Servlets can be found at:
> >
> >  http://java.sun.com/products/jsp/faq.html
> >  http://www.esperanto.org.nz/jsp/jspfaq.html
> >  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> >  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
> >
>
>===========================================================================
>To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
>JSP-INTEREST".
>Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to