5

I wrote the following program:

import sun.security.action.GetPropertyAction;

import java.security.AccessController;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class Main {

    public static void main(String[] args) {
        System.out.println(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss Z").format(new Date()));
        System.out.println(TimeZone.getDefault().getDisplayName());

        String country =AccessController.doPrivileged(new GetPropertyAction("user.country"));
        System.out.println(country);

        String javaHome=AccessController.doPrivileged(new GetPropertyAction("java.home"));
        System.out.println(javaHome);

    }
}

Then I set a GMT+3 Europe/Minsk timezone on my computer.

If I run this program with JDK6 latest release, I see that it shows me that my timezone in Java is Venezuela standard time GMT+4.30 If I run it on latest JDK7 release, it shows me Brazilian timezone GMT-3, If I run it on latest JDK8 release, it shows me Moskow time GMT+3. If I select a Volgograd GMT+3 timezone on my Win7 computer, the program works correctly in all versions of java. So is it a bug in JDK with Minsk timezone?

avalon
  • 2,231
  • 3
  • 24
  • 49
  • The output of getting the displayed name of timezone can change with JDK. Please print the id of `TimeZone.getDefault()`, too (by the method `getID()`), to enable a better analysis because displayed zone names are often ambivalent. And please also show how concretely you set up the Minsk timezone on your computer. Do you just use its displayed name - or better the ID? – Meno Hochschild Mar 25 '16 at 03:59

1 Answers1

1

The problem is caused by the fact that until 2014 there was no dedicated Europe/Minsk timezone (at least in Windows).

It appeared only after several DST and Timezone laws changes in Russia and Belarus in 2011 and 2014.

See corresponding JDK-8017129 and JDK-8067758 issues.

The changes are already taken into account in latest java releases. Older JDKs and JREs may need to be patched via Timezone Updater Tool.

OS timezone settings also have to be updated. In Windows case it means that you need to have KB2570791 and at least KB2998527 patches installed.

There is also an alternative workaround that doesn't require mentioned above patching. Just hardcode -Duser.timezone=GMT+3 in java command line parameters of needed tools or globally. This would work fine until next regulations change. )

But switching to the latest Java 8 would benefit also from stability and performance improvements.

Vadzim
  • 24,954
  • 11
  • 143
  • 151