1.datetime
对于客户端传递过来的规则时间字段,在设计数据库的时候可以考虑使用datetime字段来存储。
存储方式如下:
Date d = new Date(); try { d = TimeUtils.sdf2.parse(time); } catch (ParseException e) { // do nothing... } final Timestamp tsTime = new Timestamp(d.getTime());
2.timestamp
mysql在初始化timestamp字段的时候将默认值设置为:CURRENT_TIMESTAMP 采用Navicat设置;
在插入timestamp字段的时候将值设置为now()即可。
@Override public int saveErrlog(Errlog log) { final String sql = "INSERT INTO client_errlog (appkey, deviceid, os_version," + "activity, time, stacktrace, version, insertdate)" + "VALUES (?, ?, ?, ?, ?, ?, ?, now())"; return this.updateObject( sql, new Object[] { log.getAppkey(), log.getDevice(), log.getOsVersion(), log.getActivity(), log.getTime(), log.getStackTrace(), log.getVersion()}); }