Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java incorrect timezone

Tags:

java

timezone

I have an instance of Java which seems to be using a completely incorrect time zone. Instead of using the Australia/Sydney time zone which Windows is using, it is using the America/Caracas time zone.

I checked the Windows time through the system clock firstly, then checked HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/ and ControlSet001, ControlSet002. All are set to a Sydney time zone.

Does anybody know if this is a bug in Java, or if it is referring to a time set elsewhere?

Java version is 1.6.0_06

like image 857
Jonathan Maddison Avatar asked Jan 21 '10 02:01

Jonathan Maddison


4 Answers

Ensure you set the timezone for the JVM when starting the application:

-Duser.timezone="Australia/Sydney"
like image 181
Pool Avatar answered Oct 17 '22 02:10

Pool


Check information on the following link: http://techtavern.wordpress.com/2010/04/15/java-and-incorrect-timezone-on-windows-xp/
It shows, that there is a bug in JVM, causing reading incorrect default timezone from windows registry. There is no bug fix yet.

like image 37
Roman Avatar answered Oct 17 '22 02:10

Roman


You should update your JRE/SDK, but TZUpdater may be sufficient.

like image 6
trashgod Avatar answered Oct 17 '22 01:10

trashgod


Try in your app to get default timezone, or set timezone manually (commented line).

Little example of mine:

import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

public class Main {
    public static void main(String[] args) {
        Locale locale = Locale.getDefault();
        TimeZone localTimeZone = TimeZone.getDefault(); 
        //TimeZone localTimeZone = TimeZone.getTimeZone("Australia/Sydney");
        DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, locale);
        dateFormat.setTimeZone(localTimeZone);
        Date rightNow = new Date();
        System.out.println(locale.toString() + ": " + dateFormat.format(rightNow));
    }
}
like image 2
Robert Balent Avatar answered Oct 17 '22 02:10

Robert Balent