取Mysql时间比当前时间少13个小时

问题发现过程:

在mysql中通过,select version(); 查看到版本为5.7.27。因为以前用的都是5.6版本,现在写接口的时候,发现查出来的记录的时间总是不对,而且恰好是13个小时,经查阅相关文档,发现数据库用的时区是美国西5区的时间,而中国用的是东8区,恰好是13个小时。

解决办法:

在连接mysql的时候指定时区:jdbc:mysql://localhost:3306/db?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&autoReconnect=true

猜你喜欢

转载自www.cnblogs.com/greys/p/11669869.html