方式一:
修改配置文件(.yml):
spring:
#时间+8小时
jackson:
date-format: java.text.SimpleDateFormat #或正则yyyy-MM-dd HH:mm:ss
time-zone: GMT+8 #或UTC
方式二:
代码配置:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import javax.annotation.PostConstruct;
import java.util.TimeZone;
@SpringBootApplication
public class SpringBootStudyApplication {
//设置时区 相差8小时
@PostConstruct
void started() {
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
}
public static void main(String[] args) {
SpringApplication.run(SpringBootStudyApplication.class, args);
}
}
详见源码:
https://github.com/ZXingg/spring-boot-study