Incorrect time stamps displayed by an application or in log files

Technote (FAQ)
Problem
When there are problems with the time value returned to an application or written to the log files, a simple test can determine if the problem is with system configuration or the Java™ 2 SDK timezone offset values.
Cause
The SDK uses a combination of the SDK and the operating system default timezone to calculate the appropriate time to use when java.util.Date() is invoked. In some cases, the expected result might not be correct because the hour value has not been adjusted for daylight savings time.
Solution
Determine if the problem is related to the SDK
  • WebSphere® Application Server test using time.jsp
To test the SDK, deploy the time.jsp, which is accessible at the bottom of this technote, to an existing application. To run the time.jsp, put the file in the install_root/installedApps/node name/EAR directory/WAR directory for an existing application. Request the time.jsp from a browser; the results display to the browser and are written to the application server stdout file (see Results of timezone below).

Results of running time.jsp in the stdout file


In the stdout file, after the time.jsp is run, the following information displays:

[4/9/04 12:43:15:181 EDT] 58c81942
SystemOut U Fri Apr 09 12:43:15 EDT 2004
[4/9/04 12:43:15:181 EDT] 58c81942
SystemOut U java.util.SimpleTimeZone[id=America/New_York,
offset=-18000000,
dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,
startMonth=3,startDay=1,startDayOfWeek=1,startTime=7200000,
startTimeMode=0,endMode=2,endMonth=9,
endDay=-1,endDayOfWeek=1,
endTime=7200000,endTimeMode=0]
[4/9/04 12:43:15:181 EDT] 58c81942
SystemOut U America/New_York [4/9/04 12:43:15:181 EDT] 58c81942
SystemOut U Eastern Standard Time
[4/9/04 12:43:15:181 EDT] 58c81942 SystemOut
U Currently in daylight-savings time.

  • Java program test using Time Test.class
Copy the TimeTest.class file, available at the bottom of this technote, to the following directory:

install_root
/java/bin

At the command prompt, type:

java TimeTest

Results TimeTest

Fri Apr 09 12:45:11 EDT 2004
java.util.SimpleTimeZone[id=America/New_York,offset=-18000000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=
3,startMonth=3,startDay=1,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=2,endMonth=9,
endDay=-1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]
America/New_York Eastern Standard Time
Currently in daylight-savings time.

Gathering System Information

Determine the timezone setting that the operating system is using. For Windows® systems, the date and time properties display the timezone. For Unix® systems, issue the following command from a command prompt to display the timezone:

echo $TZ

Displaying the current values that the JVM is using

The attached JSP™ file, time.jsp, can be deployed on any application that shows symptoms of reporting the incorrect time. When the JSP is called, it returns the following values:

Current date and time

Timezone ID

Long name of the timezone in use

Currently in/not in daylight-savings time.

A table of Timezone Information that is available with the SDK that is in use.


For the java.util.SimpleTimeZone output, the fields are described below:


ID

A String giving the timezone identifier (e.g., America/New_York)

offset

An integer field giving the offset in milliseconds from GMT (or UTC). The number represents the number of milliseconds that must be added to GMT time to obtain the time in this zone. For example, the US/Eastern zone has a value of -18000000. To determine the offset in hours, offset = -18000000/( 60 * 60 * 1000)

dstSavings

An integer field giving the additional offset from GMT (or UTC) in milliseconds. (The time is calculated as offset + GMT.)

useDaylight

Boolean field set to indicate if the timezone switches to DST

startYear

An integer indicating the year in which the specified daylight savings time rule took effect.

startMonth

An integer field giving the month of the year in which daylight savings time starts. 0/January, 1/February, 2/March, 3/April, 4/May, 5/June, 6/July, 7/August, 8/September, 9/October, 10/November, 11/December

startDay

An integer giving the daylight savings ending day of the week occurrence in the month; where 1 means first occurrence, 2 means second, -1 means last occurrence, -2 means second to last occurrence, and so on.

Note that when startDayOfWeek is zero, this field represents a specific date in the month. Moreover, if startDayOfWeek is negative, this field indicates the day of the month after which the day of the week indicated by the absolute value of startDayOfWeek marks the start of daylight savings time.

startDayOfWeek

An integer field indicating the day of the week for ending daylight savings time, where 1 is Sunday and 7 is Saturday.There are some twists allowed as indicated in the startDay description above.

startTime

An integer field giving the time of day in milliseconds, starting at midnight, at which daylight savings time starts. (startTime = 7200000 / 60 * 60 * 1000)

endMonth

Same as startMonth, but for the end of daylight savings time.

endDay

Same as startDay, but for the end of daylight savings time.

endDayOfWeek

Same as startDayOfWeek, but for end of daylight savings time.

endTime

Same as startTime, but for end of daylight savings time.

Modifying the WebSphere command line arguments to use a specific timezone

If you want to specify a specific timezone that is not the same as the operating system, set the following command line argument:

-Duser.timezone=ID

An example of setting the timezone to America/Los_Angeles is:

-Duser.timezone=America/Los_Angeles

Valid timezone values display in a table when time.jsp is requested.
Related information
AIX Timezone Information












Document Information

Product categories: Software, Application Servers, Distributed Application & Web Servers, WebSphere Application Server
Operating system(s): AIX, HPUX, Linux, Multi-Platform, Solaris, Windows
Software version: 3.5, 4.0, 5.0, 5.1, 6.0
Software edition: Edition Independent
Reference #: 1173447
IBM Group: Software Group
Modified date: 2004-07-01