Error converting a String to an object Date formatted as dd / MM / yyyy

0

Good morning;

I am trying to convert a String containing the following string 2017-11-29 , to an object Date with the format dd/MM/yyyy , however it throws an error when trying to do parse() .

  

java.text.ParseException: Unparseable date: "2017-11-29"

DateFormat formateador = new SimpleDateFormat("dd/MM/yyyy");
String f = "2017-11-29";
try {
    Date fechaPeriodo = formateador.parse(f); //El error se genera aqui
    String periodo = formateador.format(fechaPeriodo);
    fechaPeriodo = formateador.parse(periodo);
} catch (ParseException e) {
    e.printStackTrace();
}
    
asked by TimeToCode 27.11.2017 в 17:45
source

1 answer

3

You have to indicate the format so that it can be parsed correctly, in your case given that the entry is "2017-11-29" the appropriate format should be "yyyy-MM-dd" .

    
answered by 27.11.2017 / 17:54
source