Hello,

I have an amazing thing in my code, when I take the date from input txt file, and i put it to an output txt file, there was not the same date, for example:
if in the input the date birth for person is:
29/07/1981

when I get the date birth for the same person it was :
Sat May 07 00:00:00 IST 1983


What's the reason of this ?

Thank you,

I guess that would really depend on how you read and then wrote that date, wouldn't it?

commented: Elementary, my dear Watson +34

I read the line like this (from the main class):

if (command.equals("addRaceDrivertoTeam")){ 	
// This method attach Race Driver to Team
String driverLicenseNumber=input.next();
String nationality=input.next();
String constructorName=input.next();
			       
boolean isUpdated=sys.addRaceDrivertoTeam(driverLicenseNumber,nationality,constructorName,input.next()+" "+input.next(), df.parse(input.next()),input.nextInt(),input.nextInt(),input.nextInt());

and This is the addRaceDrivertoTeam method that in the sys class:

public boolean addRaceDrivertoTeam(String driverLicenseNumber,String nationality,String constructorName, String fullName, Date dateOfBirth, int worldChampionships, int totalScore, int highestRaceFinish)

and the line that the main read it is:
addRaceDrivertoTeam D44KL987 Spanish Renault Fernando Alonso 29/07/1981 2 560 21

Check the date format that you are using to parse the input date. It looks like the format is reading month/day/year instead of your desired input format of day/month/year.

Note that 29 = 5 + 24. 24 months is two years and 5th month is May... now look at the output date with that in mind.

Usually when I use SimpleDateFormat I always use this method:
SimpleDateFormat.setLenient(boolean)
I set it to false in order for the parse, format methods to throw an Exception if the String I am trying to parse isn't an exact Date according to the format

Okay then, just to be stinker, what date pattern is this?

09/02/03

YY/MM/DD
YY/DD/MM
DD/MM/YY
MM/DD/YY

March 2, 2009?
Feb 3, 2009?
Feb 9, 2003?
Sep 2, 2003?

;)

But you're right, that will cut out a lot of them, just not all.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.