Mazzy
Mazzy

Reputation: 14209

read a date from a text file and put in a object date

I have to read a Date from a file and the date is written on this file in this way: dd/MM//yy but when the I read I obtain values totally different. For example: 17/11/10 became Mon Jan 04 00:00:00 CET 2010. The value is different.why?

This is the code I use:

SimpleDateFormat sdf=new SimpleDateFormat("dd/MM/YY");
Date dat=sdf.parse(reader.readLine());

Upvotes: 0

Views: 1158

Answers (2)

Peter Lawrey
Peter Lawrey

Reputation: 533640

Can you include your actual code in the question because I doubt its dd/MM//yy and dd/MM/YY is invalid.

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy");
String text = "17/11/10";
System.out.println(sdf.parse(text));

prints

Wed Nov 17 00:00:00 GMT 2010

Upvotes: 0

JB Nizet
JB Nizet

Reputation: 691893

The placeholder for year is yy, not YY. Don't know why it gives this result, though.

Upvotes: 3

Related Questions