我数据库中时间的类型是Timestamp

servlet中

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

Notice notice=new Notice();
notice.setTitle(title);
notice.setContext(context);
notice.setPublicer(name);
notice.setPublicerId(Integer.valueOf(id));

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
String here=df.format(new Date());
Timestamp ts = Timestamp.valueOf(here);//类型转换

notice.setWriteDate(ts);

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄