我从以下代码中得到错误的时区值 (IST)。来自 bugreport
import java.util.*;
import java.text.*;
class simpleTest
{
public static void main(String args[])
{
System.out.println("Simple test Josh ");
Date now = new Date();
DateFormat df = DateFormat.getDateInstance();
Calendar cal = Calendar.getInstance();
System.out.println("\n TIME ZONE :"+ cal.getTimeZone().getDisplayName());
long nowLong = now.getTime();
String s = now.toString();
System.out.println("Value of milliseconds since Epoch is " + nowLong);
System.out.println("Value of s in readable format is " + s);
}
}
都柏林的区域是错误的。它显示 IST
$ java -Duser.timezone=Europe/Dublin simpleTest
Simple test Josh
TIME ZONE :Greenwich Mean Time
Value of milliseconds since Epoch is 1408095007238
Value of s in readable format is Fri Aug 15 10:30:07 IST 2014
这个还可以
$ java -Duser.timezone=Europe/Helsinki simpleTest
Simple test Josh
TIME ZONE :Eastern European Time
Value of milliseconds since Epoch is 1408095025866
Value of s in readable format is Fri Aug 15 12:30:25 EEST 2014
值IST从何而来?
我已经检查了操作系统文件,例如/etc/localtime
bash-3.2# cd /etc
bash-3.2# ls -lrt localtime
lrwxrwxrwx 1 root root 33 Nov 16 2010 localtime -> /usr/share/zoneinfo/Europe/Dublin
/etc/sysconfig/时钟
bash-3.2# cd /etc/sysconfig/
bash-3.2# cat clock
# The ZONE parameter is only evaluated by system-config-date.
# The timezone of the system is defined by the contents of /etc/localtime.
ZONE="Europe/Dublin"
UTC=true
ARC=false
bash-3.2# pwd
最佳答案
Irish Standard Time ,这是都柏林的正确时区,缩写为 IST。
不幸的是,时区缩写并不是唯一的,正如您在 this table 中看到的那样- IST 可以解析为(至少)另外两个时区。时区缩写are not part of the related ISO standard通常不建议使用它们。
一般来说,UTC timestamps当涉及多个时区时应首选。使用 UTC,每一方只需要跟踪除自己所在时区之外的最多一个时区。此外,UTC不受DST的影响。实践,即使对于具有相同 longitude 的位置,这通常也会造成困惑。 .
关于java 程序在 linux 上报告错误的时区(显示欧洲/都柏林的 IST),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25324308/