convert String in time to Time object without Date

前端 未结 3 758
情话喂你
情话喂你 2020-12-06 06:57

i got problem to convert String time to Time object because it print together with Date. this is my code.

String time = \"15:30:18\";

DateFormat sdf = ne         


        
3条回答
  •  伪装坚强ぢ
    2020-12-06 07:19

    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.

提交回复
热议问题