5个地方可以(或者是需要)设置
1:linux服务器设置:
2、mysql安装目录下my.ini配置文件中添加
#设置默认时区
default-time-zone='+08:00'
3、spring boot 配置文件application.properties中设置spring默认时区
spring.jackson.time-zone=GMT+8
4、springboot启动类加上
@PostConstruct
void started() {
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
}
public static void main(String[] args) {
SpringApplication.run(AdminApplication.class, args);
}
5、Hibernate支持设置时区,在Springboot中增加配置如下
jpa:
show-sql: true
generate-ddl: true
hibernate:
ddl-auto: none
jdbc:
time_zone : GMT+8
6、spring boot 配置文件application.properties中设置jpa与数据库链接增加配置项默认时区
#增加
serverTimezone=GMT%2b8
例如
spring.datasource.url = jdbc:mysql://localhost:3306/referee?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2b8&useLegacyDatetimeCode=false
或者:
serverTimezone=CTT CTT就是中国
也可以选择东8区的Hongkong、Asia/Shanghai或者Asia/Hongkong作为参数
serverTimezone=Hongkong 香港