Pergunta

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!

Foi útil?

Solução

Use capital MM for month; mm is minutes.

Outras dicas

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

Check this Reference

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top