//将时间字符串转Timestamp类型
public static Timestamp string2Time(String dateString) throws ParseException {
DateFormat dateFormat;
dateFormat = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss", Locale.ENGLISH);
dateFormat.setLenient(false);
java.util.Date timeDate = dateFormat.parse(dateString);//util类型
Timestamp dateTime = new Timestamp(timeDate.getTime());//Timestamp类型,timeDate.getTime()返回一个long型
return dateTime;
}
Timestamp t = string2Time("2018-07-27 12:25:00");
//组织sql语句
String sql = "insert into table values('"+t+"');";
Java在mysql数据库中插入datatime时间数据
猜你喜欢
转载自blog.csdn.net/qq_27124771/article/details/81235178
今日推荐
周排行