如何强制Spring Boot JVM进入UTC时区?
我看到Java时区为GMT / UTC
我试过了
- mvn spring-boot:run -Dexec.args =“-Duser.timezone = GMT”
- mvn spring-boot:run -Dexec.args =“-Duser.timezone = UTC”
user.timezone=UTC
在config/application.properties
user.timezone=GMT
在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>
mvn spring-boot:运行-Dspring-boot.run.jvmArguments =“-Duser.timezone = UTC”
但它打印出来
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" title="Spring Boot">Spring Boot 1.5.19,Java 8
回答:
如果要将JVM选项从Maven Spring Boot插件传递到派生的Spring Boot应用程序,请使用spring-
boot.run.jvmArguments属性:
<properties> <spring-boot.run.jvmArguments>-Duser.timezone=UTC</spring-boot.run.jvmArguments>
</properties>
这等效于命令行语法:
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Duser.timezone=UTC"
或运行完全打包的Spring Boot应用程序时:
java -Duser.timezone=UTC -jar app.jar
以上是 如何强制Spring Boot JVM进入UTC时区? 的全部内容, 来源链接: utcz.com/qa/425120.html