以下两种方法是否完全等效,以确保 Java 应用程序在 UTC 中运行?
Starting the JVM with the 'user.timezone' parameter:
java -jar MyJar.jar -Duser.timezone=UTC
Having the following method executed from the main() method (Java 8)
private static void setUtcTimezone() { ZoneId zoneId = ZoneId.of("UTC"); TimeZone zone = TimeZone.getTimeZone(zoneId); TimeZone.setDefault(zone); }
我希望让应用程序在UTC时间下运行,不再提供可选项,因此不建议使用JVM参数方法。