Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
287 views
Welcome To Ask or Share your Answers For Others

1 Answer

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...