문제

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!

도움이 되었습니까?

해결책

Use capital MM for month; mm is minutes.

다른 팁

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

Check this Reference

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top