问题:在app server中的正确时间,在数据库中是错误的
我在中国,时区是UTC 8
我用hibernate.实体定义如下(语言:Scala)
class CargoJournal {
@Type(`type`="org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
var deliverTime: LocalDateTime = _
@Temporal(TemporalType.TIMESTAMP)
@Column(nullable=false)
var logDate:Date = _
}
我打开hibernate日志,在我的app服务器中看到以下内容.当前时间是Thu Sep 13 11:08:44 CST 2012
insert into wms_history_cargo_journal (deliver_time, log_date)
binding parameter [1] as [TIMESTAMP] - 2012-09-13 11:08:44.25
binding parameter [2] as [TIMESTAMP] - Thu Sep 13 11:08:44 CST 2012
在我的数据库服务器:
mysql> select timediff(now(),convert_tz(now(),@@session.time_zone,'+00:00'));
+----------------------------------------------------------------+
| timediff(now(),convert_tz(now(),@@session.time_zone,'+00:00')) |
+----------------------------------------------------------------+
| 08:00:00 |
+----------------------------------------------------------------+
所以mysql时区是对的. UTC 8
从mysql中选择后:
mysql> SELECT deliver_time, log_date FROM wms_history_cargo_journal;
+---------------------+---------------------+
| deliver_time | log_date |
+---------------------+---------------------+
| 2012-09-13 11:08:44 | 2012-09-13 03:08:44 |
+---------------------+---------------------+
log_date错了!