0

I need to convert an array of strings into the type Date in Java. I looked up some sample codes, which they all pretty much ask to do the same straight forward thing. This is what I'm doing:

  String[] dateString = { "2014/05/01", "2014/05/02", "2014/05/03", "2014/05/04", "2014/05/05"};
        Date[] dt = new Date[5];
        for(int i=0;i<count;i++){
            dt[i]= new SimpleDateFormat("yyyy/mm/dd").parse(dateString[i]);
        }

The issue is on the line inside the loop I get an error that states: "Unhandled Exception by ParseException". Eclipse suggests me to surround it with a try and catch block, which I did. It now runs, but the dates I am getting in the dt array are not matching to the ones I'm putting in. I guess I am getting some kind of default value, which starts and January 1st 2014.

Anyone know what this is and how to solve it?

Thank you!

theJuls
  • 6,788
  • 14
  • 73
  • 160

2 Answers2

5

Use capital MM for month; mm is minutes.

rgettman
  • 176,041
  • 30
  • 275
  • 357
  • Ohhh! Now it worked! Originally I had it all in capital letters, but I got an exception because of the Ys, so I put it all in lower case. Thanks! – theJuls May 15 '14 at 21:23
  • Yes, the case makes a difference for each letter code. – rgettman May 15 '14 at 21:24
1

For month, you need to use MM, not mm. mm represents minutes

Check this Reference

Bhushan
  • 18,329
  • 31
  • 104
  • 137
  • Perfect! Thanks! Originally had it liked that, but changed it all after I got an exception because of the capital Ys... – theJuls May 15 '14 at 21:23