log(2 different dates):
START TIME BEFORE PARSE: 06/27/2012 09:00
START TIME AFTER PARSE : Thu Mar 06 09:00:00 EET 2014
START TIME BEFORE PARSE: 07/06/2012 09:00
START TIME AFTER PARSE : Thu Jun 07 09:00:00 EEST 2012
code :
DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");
Date date = sdf.parse(time);
System.out.println("TIME BEFORE PARSE: " + time);
System.out.println("TIME AFTER PARSE : " + date);
Why does it mess up the year? How to get it to work?
You use the pattern dd/MM/yyyy to parse the date 06/27/2012. I doubt 27 is a month. The appropriate format is MM/dd/yyyy.
The DateFormat is lenient by default, and will thus consider 27 as a valid month: 2 years + 3 months, so you end up in March, 2 years later.
In your example date format is wrong. You have give "dd/MM/yyyy HH:mm" which should be "MM/dd/yyyy HH:mm"
Because you inverted the month with the date:
There is not 27th month in a year.
You have used the pattern dd/MM/YYYY , but you have entered the date as MM/dd/YYYY, causing you this weird behaviour..
The month in the first example is
27
which isn't valid in any calendar I'm aware of. (You probably just got the day/month ordering wrong, either on your input, or in the format you've chosen.)