问题:在应用程序服务器的正确时间,数据库中出错。
我在中国,时区是UTC + 8
我使用休眠。实体定义如下(语言:Scala)
class CargoJournal {
@Type(`type`="org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
var deliverTime: LocalDateTime = _
@Temporal(TemporalType.TIMESTAMP)
@Column(nullable=false)
var logDate:Date = _
}我打开休眠日志,在我的应用程序服务器中查看以下内容。当前时间为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错误!