Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date validation algorithm!!!

Status
Not open for further replies.

jazz24

Technical User
Oct 22, 2001
1
AU
Hi all,

I am in the process of doing my java assignment and have no idea where to start...as I need to perform solution algorithm: object table, Pseudocode: design(logic), syntax..testing, desk checking, execution and so forth.

I would like some directions as where can I find "date validation algorithm"...also any other sample exercises that might come handy with regards to designing and writing java application using JDK.

any and all help appreciated!

Regards
Jazz
 
hi

public static boolean isDate(String strDate) {

if( strDate == null ) return false;

try {
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");

Date date = formatter.parse(strDate);

String strDate2 = formatter.format(date);

// analyse de la date initiale
StringTokenizer tokens = new StringTokenizer(strDate,"/");

if( tokens.countTokens() != 3 )
return false;

int day = Integer.parseInt(tokens.nextToken());
int month = Integer.parseInt(tokens.nextToken());
int year = Integer.parseInt(tokens.nextToken());

// analyse de la date parsée par java
StringTokenizer tokens2 = new StringTokenizer(strDate2,"/");

if( tokens2.countTokens() != 3 )
return false;

int day2 = Integer.parseInt(tokens2.nextToken());
int month2 = Integer.parseInt(tokens2.nextToken());
int year2 = Integer.parseInt(tokens2.nextToken());

if( day != day2 || month != month2 || year != year2 )
return false;

return true;

} catch (ParseException pe) {
return false;
}

} manu0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top