1、我们设置mysql连接,在连接语句后面加上
&serverTimezone=GMT+8
2、然后修改jackson配置
#spring
spring:
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
3、修改启动类
在启动类中,添加这个方法
/**
* 设置时区
*/
@PostConstruct
void setDefaultTimezone() {
TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
}
然后在启动类的main方法中,设置时区
public static void main(String[] args) {
TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
SpringApplication.run(AdminApplication.class, args);