Friday, April 25, 2008

Oracle 10g timezones and setting the Java timezone

To see your session and database timezones:
SELECT sessiontimezone, dbtimezone FROM dual;
To set them:
ALTER database SET TIME_ZONE = '-07:00';
ALTER session SET TIME_ZONE = '-07:00';
Alternatively you can set it by supplying a region which exists in the following list:
To set the JVM timezone append the following option when calling java:
Java stores the supported timezones in files located at:
To set the timezone within your code, which is sometimes neccessary because OC4J seems to ignore my -Duser.timezone option:
java.util.TimeZone tz = java.util.TimeZone.getTimeZone("America/Vancouver");

Here is a JSP page to display some time and timezone related information:

<%@ page language=\"java\" contentType=\"text/html; charset=ISO-8859-1\"
<%@ page import=\"
  java.text.DateFormat\" %>
<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"\">
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">
<title>TimeZone Test</title>
Your current timezone is: <%= java.util.TimeZone.getDefault().toString() %>
The current time is: <%= (new java.util.Date()).toString() %>
The value of the user.timezone property is: <%= System.getProperty(\"user.timezone\") %>
The date using DateFormat is: <%= DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL).format(new Date()) %>

No comments: