Search code examples
javadatetimejvmhour

JVM Timezone is off by one hour


Using Java 6 update 30 on a Windows XP machine. Updating Java or Windows is not an option.

I need a way to change the internal Java clock back one hour to match the system time. The machine is in Russia and Windows system time is correct, but the Java time is off by one hour, probably due to DST.

I have tried changing JVM parameters as well as modifying the deployment.properties file (to change the timezone), adding a variable to the environment/system variables path also did not work, and attempted the timezone updater tool provided by Oracle. The first three do not change any parameters and the updater tool crashes, and says "Cannot find JRE/JDK files".

Is there any other way to permanently/properly change the time that Java is using.

example: Current Time : 7:20:17 PM TimeZone : sun.util.calendar.ZoneInfo [id="Europe/Moscow", offset=14400000, dstSavings=0, useDaylight=false, transitions=78, LastRule=null]

Required Time : 6:20:17 PM TimeZone : sun.util.calendar.ZoneInfo [id="Europe/Moscow", offset=14400000, dstSavings=0, useDaylight=false, transitions=78, LastRule=null]


Solution

  • As your first two options - upgrade the JVM and use tzupdater - are not possible, you will have to use a workaround. You can set the default timezone for the JVM using the user.timezone property. You will need to set the timezone to a zone one hour away from the actual timezone to compensate for the 2014 changes.

    Russian timezones available are

    Europe/Kaliningrad
    Europe/Moscow
    Europe/Samara
    Europe/Volgograd
    Asia/Yekaterinburg
    Asia/Novokuznetsk
    Asia/Novosibirsk
    Asia/Omsk
    Asia/Krasnoyarsk
    Asia/Irkutsk
    Asia/Yakutsk
    Asia/Sakhalin
    Asia/Vladivostok
    Asia/Anadyr
    Asia/Kamchatka
    Asia/Magadan