我看到 强制 Java 时区为 GMT/UTC
我试过了
config/application.properties
user.timezone=UTC
user.timezone=GMT
在 pom.xml 中:
<插件><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><配置><属性><spring-boot.run.jvmArguments>-Duser.timezone=UTC</spring-boot.run.jvmArguments></属性></配置></插件>
但它会打印出来
System.out.println(TimeZone.getDefault());
<块引用>
sun.util.calendar.ZoneInfo[id="America/New_York",offset=-18000000,dstSavings=3600000,useDaylight=true,transitions=235,lastRule=java.util.SimpleTimeZone[id=America/New_York,offset=-18000000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]]
Spring Boot 1.5.19,Java 8
使用 spring-boot.run.jvmArguments
属性 如果您想将 JVM 选项从 Maven Spring Boot 插件传递到分叉的 Spring Boot 应用程序:
<spring-boot.run.jvmArguments>-Duser.timezone=UTC</spring-boot.run.jvmArguments></属性>
这相当于命令行语法:
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Duser.timezone=UTC"
或在运行完全打包的 Spring Boot 应用程序时:
java -Duser.timezone=UTC -jar app.jar
I saw Force Java timezone as GMT/UTC
I tried
user.timezone=UTC
in config/application.properties
user.timezone=GMT
In the pom.xml:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<properties>
<spring-boot.run.jvmArguments>-Duser.timezone=UTC</spring-boot.run.jvmArguments>
</properties>
</configuration>
</plugin>
But it prints out
System.out.println(TimeZone.getDefault());
sun.util.calendar.ZoneInfo[id="America/New_York",offset=-18000000,dstSavings=3600000,useDaylight=true,transitions=235,lastRule=java.util.SimpleTimeZone[id=America/New_York,offset=-18000000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]]
Spring Boot 1.5.19, Java 8
Use spring-boot.run.jvmArguments
property if you want to pass JVM options from Maven Spring Boot Plugin to forked Spring Boot application:
<properties>
<spring-boot.run.jvmArguments>-Duser.timezone=UTC</spring-boot.run.jvmArguments>
</properties>
This is be equivalent to command line syntax:
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Duser.timezone=UTC"
or when running a fully packaged Spring Boot application:
java -Duser.timezone=UTC -jar app.jar
这篇关于如何强制 Spring Boot JVM 进入 UTC 时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!