cast a String to sql time

前端 未结 3 1175
失恋的感觉
失恋的感觉 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:41

    You can use this code:

    java.sql.Time.parse("String");
    

    But that's deprecated, and replaced by DateFormat Parse.

    0 讨论(0)
  • 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);
    
    0 讨论(0)
  • 2020-12-19 11:51
    java.sql.Time.valueOf("String");
    
    0 讨论(0)
提交回复
热议问题