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!

1
  • mm is minutes, try MM Commented May 15, 2014 at 21:20

2 Answers 2

5

Use capital MM for month; mm is minutes.

Sign up to request clarification or add additional context in comments.

2 Comments

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!
Yes, the case makes a difference for each letter code.
1

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

Check this Reference

1 Comment

Perfect! Thanks! Originally had it liked that, but changed it all after I got an exception because of the capital Ys...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.