在数据库中数据类型为Datetime,反向生成到java后台数据类型为timestamp,java获取的当前时间为Date,我们需要将Date类型转换为String类型并选择自己想要的展示形式,,转为String类型后我们将String类型转换成timestamp即可。
· Date opeartime= new Date();//获取服务器当前时间
SimpleDateFormat time = new SimpleDateFormat ("yyyy-MM-dd hh:mm:ss");//将当前时间转化成String格式
Timestamp timea=Timestamp.valueOf(time.format(opeartime)) ;//将String强制转换成timestamp格式
网友评论