Java giving incorrect year values
- by whistler
Something very, very strange is occurring in my program, and I'm wondering if anyone out there has seen this occur before. And, if so, how to fix it.
Basically, I am parsing an csv file...no problem there. One column contains a date and I am taking it in as a String and changing to a Date object. Again, no problem there. The code is as follows:
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yy hh:mm");
Date initialDate = new Date();
try {
initialDate = dateFormat.parse(rows.get(0)[8]);
System.out.println(initialDate);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Of course, I'm parsing other columns as well (and those are working fine). So, when I run my program for a small csv file (2.8 MB), the dates come out (i.e. are parsed) perfectly. However, when I run the program for a large csv file (25 MB), the dates are a hot mess. For example, take a look at the year values I am getting (the following is just a tiny portion of the println output from the code above):
1000264 at Sun Nov 05 15:30:00 EST 2186
1000320 at Sat Mar 04 17:30:00 EST 2169
1000347 at Sat Apr 01 09:45:00 EDT 2169
1000413 at Tue Jul 09 13:00:00 EDT 2182
1000638 at Fri Dec 11 13:45:00 EST 2167
1000667 at Wed Dec 10 10:00:00 EST 2188
1000690 at Mon Jan 02 13:00:00 EST 2169
1000843 at Thu Feb 11 13:30:00 EST 2196
In actuality, the years are in the realm of 1990-2006 or so. Again, this does not happen with the small csv file.
Does anyone know what's going on here and how I can fix it? I need to process the large csv file (the small one was just for testing purposes).
By request, here are the actual dates in the csv file and after that the value given by the code above:
5/20/03 15:30
5/20/03 15:30
8/30/04 9:00
8/30/04 9:00
12/20/04 10:30
12/20/04 10:30
Sun Nov 05 15:30:00 EST 2186
Sun Nov 05 15:30:00 EST 2186
Sun Nov 05 15:30:00 EST 2186
Thu Dec 08 09:00:00 EST 2196
Tue Dec 12 10:30:00 EST 2186
Tue Dec 12 10:30:00 EST 2186