Convert wrong string string to be displayed [duplicate]

1

I have a string in the following format 2017-12-08 , however I need to display it formatted for the user as follows: 08/12/2017 , I thought about using SimpleDateFormat variable is in Date format, and I am not consequently converting that String to Date .

How could I do this, or is there any way to format this string to be displayed the way I need the user?

    
asked by anonymous 08.12.2017 / 17:42

1 answer

1
String strDate = "2017-12-08";

SimpleFormatDate oldFormat =  new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat newFormat = new SimpleDateFormat("dd/MM/yyyy");

System.out.print(newFormat.format(oldFormat.parse(strDate)));

See working at ideone: link

However, I recommend that you consider working with new java version 8 datetime API

    
08.12.2017 / 17:53