-2

I have a simple block of code as follows which takes in a date using SimpleDateFormat, creates a Date object and spits it out textually again

SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/YYYY HH:mm");
Date date = dateformat.parse("23/10/2014 14:00");
System.out.println(date.toString());

I was expecting date.toString() to spit out a similar representation of the date I'd entered, but instead I this: Mon Dec 30 14:00:00 GMT 2013 which isn't the same date at all as I typed in. (though the time is the same correct.)

What's wrong?

Odyssey
  • 89
  • 9

1 Answers1

3

Choosing a little y for year fixes the issue, and the output changes to

Thu Oct 23 14:00:00 BST 2014

  • Y represents Week year
  • y represents Year

The code now reads

SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy HH:mm");
Date date = dateformat.parse("23/10/2014 14:00");
System.out.println(date.toString());
Odyssey
  • 89
  • 9