我的系统时区是(UTC+02:00)伊斯坦布尔。当我运行一个简单的java程序来显示时区时,它显示"America/Rio_Branco“(这是不正确的)。但当我设置为任何其他时区时,它都能正常工作。此外,我使用tzupdater.jar (我将路径设置为..\jre\lib)更新了我的jre。可能的原因是什么?
我的代码是:
import java.util.*;
import java.text.*;
public class Time
{
public static void main(String[] args){
TimeZone timeZone = TimeZone.getDefault();
System.out.println("timeZone : "+timeZone);
}
}发布于 2014-12-04 19:33:55
我用来自jre8的文件替换了tzmappings文件,它解决了我的问题。
发布于 2014-12-04 18:34:40
如果你阅读了JavaDoc,你会看到:
Gets the default TimeZone for this host. The source of the default TimeZone may vary with implementation.因此,你得到"America/ Rio _Branco“的原因是因为你的主机(操作系统)的JDK实现认为你在Rio Branco的时区。在评论中你提到你正在运行Windows7,所以这可能是因为Windows在某个地方错误地设置了时区。我认为Windows上的Java在注册表中进行检查:
HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/TimeZoneInformation也许你可以检查这个值?
https://stackoverflow.com/questions/27290890
复制相似问题