Search code examples
javawebsphere

websphere jre timezone incorrect


We have two linux application servers at my work both with websphere 6.1 installed. I've written a simple stand alone java application to print the current time.

    public static void main(String[] args) {
            TimeZone tz = TimeZone.getDefault();
            System.out.println("the default timezone is " + tz.getDisplayName(true, TimeZone.LONG));
            System.out.println("the default timezone ID is " + tz.getID());
            System.out.println("useDaylightTime = " + tz.useDaylightTime());
    }

On box application server a I get...

the default timezone is Eastern Summer Time (New South Wales)
the default timezone ID is Australia/Sydney
useDaylightTime = true

On box application server b I get...

the default timezone is GMT+10:00
the default timezone ID is GMT+10:00
useDaylightTime = false

I want application server b to be the same as a. Can someone assist me with what I might need to do to make this happen?

thanks


Solution

  • When using the getDefault() method, if not cached, Java will

    Use the user.timezone property value as the default time zone ID if it's available.
    Detect the platform time zone ID.
    Use GMT as the last resort if the given or detected time zone ID is unknown.
    

    Based on your reported output, it appears as though the application server b does not have the user.timezone property set. According to http://chandank.com/application-server/was/set-timezone-in-websphere-application-server, you can set the timezone following these steps

    1. Start the administrative console.
    2. In the topology tree, expand Servers >> Application Servers.
    3. Click on application server for which you want to set the time zone
    4. On the application server page, click Process Definition>>Java Virtual Machine>>Custom Properties>>New
    5. Specify user.timezone in the Name field and timezone in the Value field, where timezone is the supported value for your time zone.
    6. Click Apply/ok
    7. Save the configuration
    
    
    ex :  Name - user.timezone
         value - Asia/Singapore
    

    So I would verify that it is set properly for your b system. In your case you would change Asia/Singapore to Australia/Sydney

    If the procedure above doesn't work (for whatever reason), I just setting your timezone via the clock settings should fix it assuming that you can do that. I do not have a Websphere system available to test it.