首页 > 解决方案 > 在 Spring Boot 中更改 serverTimezone

问题描述

我想将 serverTimezone 更改为 GMT+3。我试试这个但不工作

spring.datasource.url=jdbc:mysql://localhost:3306/example?useSSL=false&serverTimezone=GMT+3&useLegacyDatetimeCode=false
Caused by: java.sql.SQLException: No timezone mapping entry for 'GMT 3'

但如果我运行它,它正在使用 GMT-3

spring.datasource.url=jdbc:mysql://localhost:3306/example?useSSL=false&serverTimezone=GMT-3&useLegacyDatetimeCode=false

如何将其更改为 GMT+3 ?

标签: spring-bootjdbc

解决方案


请在主启动应用程序中覆盖 PostConstruct,如下所示

@PostConstruct
public void init()
{
    TimeZone.setDefault(TimeZone.getTimeZone("Asia/Kolkata"));   
}

将 Asia/Kolkata 替换为您的时区


推荐阅读