cast a String to sql time

前端 未结 3 1183
失恋的感觉
失恋的感觉 2020-12-19 11:08

How we cast a string into time type with mysql in java So String------->java.sql.time

thanks.

3条回答
  •  半阙折子戏
    2020-12-19 11:45

    It depends entirely on the format of your String, so I would use a SimpleDateFormat to parse the string into a java.util.Date; then you can extract the millisecond time value from that Date and pass it into a java.sql.Time(). Like this:

    String s = /* your date string here */;
    SimpleDateFormat sdf = new SimpleDateFormat(/* your date format string here */);
    long ms = sdf.parse(s).getTime();
    Time t = new Time(ms);
    

提交回复
热议问题