1、mysql的datetime类型对应java的java.sql.Timestamp
2、更新方法
Date date = new Date(); //Date是java.util.Date
Timestamp time1 = new Timestamp(date.getTime());
Timestamp time2 = new Timestamp(System.currentTimeMillis());
Timestamp time3 = new Timestamp(Calendar.getInstance().getTimeInMillis());
3、注意datetime类型依赖于数据库的时区
在数据库jdbc配置的url中,如果是serverTimezone=UTC,存入的时间会比当前时间少8个小时
需要改成serverTimezone=Asia/Shanghai
参考资料:
https://blog.csdn.net/testcs_dn/article/details/81455898/
https://blog.csdn.net/qq_40634846/article/details/105139131