Use the same SimpleDateFormat that you used to analyze it:
String time = "15:30:18"; DateFormat sdf = new SimpleDateFormat("hh:mm:ss"); Date date = sdf.parse(time); System.out.println("Time: " + sdf.format(date));
Remember that a Date object always represents a combined date / time value. It cannot correctly represent a value only for a date or time, so you should use the correct DateFormat to make sure that you only see the parts that you want.
skaffman
source share