mysql数据库date类型时间取出多了8个小时

数据库时间如下:

 数据库配置

spring:
datasource:
username: root
password: root
url: jdbc:mysql://localhost:3306/ag_admin?&serverTimezone=UTC&useUnicode=true&characterEncoding=UTF8&useSSL=false
driver-class-name: com.mysql.jdbc.Driver

查询出数据如下:j多了8个 小时

原因由于我们大部分使用的时间默认时区是东八区,而数据库配置的 serverTimezone=UTC 是世界标准时间(美国时间),所以差了8个小时。

解决方案:

时区改为东八区

serverTimezone= GMT%2B8

原文地址:https://www.cnblogs.com/lfyu/p/12523222.html