[program-java] Re: date validation

Hi Adrian!

It seems wonderful and exactly what I've been looking for.
How many years you've been working with Java, and how did you learn it?

Thank you very much,
Anna

-----Original Message-----
From: program-java-bounce@xxxxxxxxxxxxx
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Adrian Beech
Sent: Thursday, January 22, 2009 3:34 PM
To: program-java@xxxxxxxxxxxxx
Subject: [program-java] Re: date validation

G'day Anna,

Contenplate the code snipets below adding them in the appropriate places in
your application.

import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Date;

private static final String DATE_FORMAT = "dd/mm/yyyy";

SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
Date parsedDate = null;

String testString = "22/01/2009";

try
{
  parsedDate = dateFormat.parse(testString);
}
catch (ParseException e)
{
  ...
}

I would suggest that you check out the documentation for DateFormat and
SimpleDateFormat for the various tokens and there meaning.  I think it would
also be possible to get the localised date format and use this rather than
hard coding the expected pattern.  I've not had the need to do this as the
stuff I write is in house and thus for the sake of a shortcut, yudda, yudda.

Hope this is of some help.

Cheers.
AB

-----Original Message-----
From: program-java-bounce@xxxxxxxxxxxxx
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Anna Giller
Sent: Friday, 23 January 2009 6:18 AM
To: program-java@xxxxxxxxxxxxx
Subject: [program-java] Re: date validation

Jim:

In COBOL this routine would look about the same and as long.
I'm trying to use the advantages of Java. 
Did you ever meet the class Date Validation that J.R. was talking about?

Thanks,
Anna



-----Original Message-----
From: program-java-bounce@xxxxxxxxxxxxx
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Corbett, James
Sent: Thursday, January 22, 2009 3:13 PM
To: program-java@xxxxxxxxxxxxx
Subject: [program-java] Re: date validation

Anna:

Why make it complex if you don't have to.... It works, it's clean and
best of all it's free.

J. 

-----Original Message-----
From: program-java-bounce@xxxxxxxxxxxxx
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Anna Giller
Sent: January 22, 2009 14:55
To: program-java@xxxxxxxxxxxxx
Subject: [program-java] Re: date validation

Jim:

Thank you for this routine, but I have similar one.
I'm looking for validation using Java classes like DateFormat,
SimpleDate or any other one.

Thanks,
Anna
-----Original Message-----
From: program-java-bounce@xxxxxxxxxxxxx
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Corbett, James
Sent: Thursday, January 22, 2009 2:18 PM
To: program-java@xxxxxxxxxxxxx
Subject: [program-java] Re: date validation

Anna:

Using date format of YYYY/MM/DD 

try{
                                int m =
Integer.valueOf(repPeriodEndDate.substring(5, 7)).intValue();
                                int d =
Integer.valueOf(repPeriodEndDate.substring(8)).intValue();

                                if(m==1 || m==3 || m==5 || m==7 || m==8
|| m==10 || m==12){
                                        if(d==31){
                                                dayValidation = true;
                                        }
                                }else if(m==4 || m==6 || m==9 || m==11){
                                        if(d==30){
                                                dayValidation = true;
                                        }

                                }else if(m==2){
                                        if(d==28 || d==29){
                                                dayValidation = true;
                                        }

                                }
                        }catch(NumberFormatException nfe){
                                nfe.printStackTrace();
                        } 

-----Original Message-----
From: program-java-bounce@xxxxxxxxxxxxx
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Anna Giller
Sent: January 22, 2009 13:39
To: program-java@xxxxxxxxxxxxx
Subject: [program-java] date validation

Jim:

 

Do you have a date validation routine?

I have one, it's ugly enough. It checks the value of the month, then the
value of the day, compares it with the array of valid values.

I need more professional one, that uses Java classes.

 

I was also looking for a numeric field validation, but just found one.

And want to share it with our people.

It's neat, isn't it?

I'm looking for a date validation routine in the similar style.

 

Thank you and the code follows.

Anna 

 

  int number=0;   

      while (number == 0) {   

    String input=JOptionPane.showInputDialog("\n\tEnter numeric
value.");   

    try{   

number=Integer.parseInt(input);   

    }catch(NumberFormatException nfe)   

    {   

Number = 0;   

    }   

 








__________ NOD32 3790 (20090122) Information __________

This message was checked by NOD32 antivirus system.
http://www.eset.com





Other related posts: