I want to convert String to a date field in Java. Currently, I have this string with me and I want to convert into date(MM/DD/YYYY)
field. Any suggestion?
String str = "2019-12-11 00:00:00"
The output I want is 11/12/2019
.
I want to convert String to a date field in Java. Currently, I have this string with me and I want to convert into date(MM/DD/YYYY)
field. Any suggestion?
String str = "2019-12-11 00:00:00"
The output I want is 11/12/2019
.
There are probably more elegant solutions for this problem, but this little method will suffice for your specific case:
private static String formatDate(String str)
{
String[] split = str.split(" ");
String[] split2 = split[0].split("-");
String result = split2[2].concat("/").concat(split2[1]).concat("/").concat(split2[0]);
return result;
}