Use the same SimpleDateFormat
that you used to parse 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, the Date
object always represents a combined date/time value. It can't properly represent a date-only or time-only value, so you have to use the correct DateFormat
to ensure you only "see" the parts that you want.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…