简体   繁体   中英

Java TimeZone update

My system time zone is (UTC+02:00) Istanbul. When I run a simple java program to display time zone, it displays "America/Rio_Branco" (which is incorrect). But when I set to any other time zones it works correctly. Also I updated my jre using tzupdater.jar (I set my path to ..\\jre\\lib). What could be the reason?

My code is :

import java.util.*;
import java.text.*;
public class Time
{
    public static void main(String[] args){
        TimeZone timeZone = TimeZone.getDefault();
        System.out.println("timeZone : "+timeZone);
    }
}

我用来自jre8的文件替换了tzmappings文件,它解决了我的问题。

If you read the JavaDoc you'll see this:

Gets the default TimeZone for this host. The source of the default TimeZone may vary with implementation.

Thus reason you're getting "America/Rio_Branco" is because the JDK implementation for your host (operating system) thinks you are in Rio Branco's timezone. In the comments you mention you're running Windows 7, so it might be the case that Windows incorrectly has a timezone set somewhere. I think Java on Windows checks in the registry here:

HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/TimeZoneInformation

Maybe you can check that value?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM