I have the String 201510251010 that represents the date 2015/10/25 10:10. I want obtain the date as String with the second format.
I have this code:
String myString = "201510151235";
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmm");
SimpleDateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
Date d = dateFormat.parse(myString);
String s = dateFormat2.format(d);
It works but I think this is ugly code. Is there a way to do the same with regex and replaceAll or something similar?