我在我的服务器上使用 Tomcat 和 java 1.8。 2023 年 3 月 20 日之后 DST(夏令时)不更改当地时间 DST 在亚洲/德黑兰时区(3 月 21 日至 9 月 22 日之间标准时间提前 1 小时-伊朗官方时钟提前一小时直到 2023 年,此规则被取消今年)。但是基于 JVM 的应用程序(如 tomcat)启用 DST,并且 tomcat-8 中 new Date() 的返回值比系统时间提前 1 小时。 系统日期的返回是:
human@PC-1130:~$ date
Mon Apr 3 10:12:07 AM +0330 2023
操作系统是 Debian 和 CentOs7:
human@PC-1130:~$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 7 (wheezy)"
NAME="Debian GNU/Linux"
VERSION_ID="7"
VERSION="7 (wheezy)"
ID=debian
我的JDK版本是1.8:
human@PC-1130:~$ java -version
java version "1.8.0_152"
Java(TM) SE Runtime Environment (build 1.8.0_152-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)
我写了一些示例代码来检查 JVM Date() 返回值:
public class Main {
public static void main(String[] args) {
System.out.println(new java.util.Date());
}
}
返回值为:
human@PC-1130:~$ javac Main.java
human@PC-1130:~$ java Main
Mon Apr 03 11:12:22 IRST 2023
如您所见,JVM 返回日期比系统日期提前 1 小时。 如何使用环境变量在 JVM 中禁用 DST?