Springboot time zone problem

1. Add the

@PostConstruct

void   setDefaultTimezone()  {
  TimeZone.setDefault(TimeZone.getTimeZone(“Asia/Shanghai”));
}  
2. Add the

 ##  json   setting
spring.jackson.date-format=yyyy-MM-dd   HH:mm:ss
spring.jackson.time-zone=Asia/Shanghai  
 
3. Add the

public static void main(String[] args) {

    TimeZone.setDefault(TimeZone.getTimeZone(“Asia/Shanghai”));

  SpringApplication.run(BaseMicroServiceApplication.class, args);

}

 
// Otherwise, there will be 8-hour time difference on the server

Or in the database:

After logging in as root, set global time_ zone=’+8:00′;

 
 
Mysql database has time zone setting, and the system time zone is used by default

You can query the current time zone through the following statement

show variables like ‘%time_ zone%’;


Read More: