Convert Wrong sequence string to display

Asked

Viewed 47 times

1

I own a string in the following format 2017-12-08, but need to display it formatted for the user as follows: 08/12/2017, I thought I’d use the SimpleDateFormat but for this I need the variable to be in the format Date, and I am not therefore converting that String in Date.

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

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 it working on ideone: https://ideone.com/6lTkua

However, I recommend that you evaluate working with the new java date API version 8

Browser other questions tagged

You are not signed in. Login or sign up in order to post.