美文网首页
LocalDateTime 时区问题

LocalDateTime 时区问题

作者: 和女朋友一起开发的游戏 | 来源:发表于2019-08-27 09:21 被阅读0次

LocalDateTime默认是不包含时区信息的,会取当前机器时间的时区,其实一般情况下,是没有问题的。

但是当我查询或插入MySQL数据库里的数据时,LocalDateTime 会相差8小时,最后才定位到,原来是使用MySQL5.7版本后,更新了Springboot配置文件中的驱动设置 driver-class-name: com.mysql.cj.jdbc.Driver,由此造成 url: jdbc:mysql://127.0.0.1:3306/sparchetype?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT 里面的serverTimezone=GMT有问题,经过网上资料的解决方案是将serverTimezone=GMT更改serverTimezone=Hongkong即可。

相关文章

网友评论

      本文标题:LocalDateTime 时区问题

      本文链接:https://www.haomeiwen.com/subject/crdsectx.html