Wednesday, November 7, 2012

Oracle DB, SessionTimeZone, and Java

this SQL:

select SESSIONTIMEZONE from dual;

returns "Europe/Berlin"

(see http://docs.oracle.com/cd/B28359_01/server.111/b28286/functions150.htm )

"SESSIONTIMEZONE returns the time zone of the current session. The return type is a time zone offset (a character type in the format '[+|]TZH:TZM') or a time zone region name, depending on how the user specified the session time zone value in the most recent ALTER SESSION statement.... using the ORA_SDTZ environment variable "

The JDBC driver sets on the Session some date/time session parameters:
http://docs.oracle.com/cd/E13222_01/wls/docs100/jdbc_drivers/oracle.html



This code: 

import java.util.Calendar;

public class TimeZoneHelper {

    public static String getTimeZoneInfo()
    {
      String result = "";
      Calendar now = Calendar.getInstance();
      result += now.getTimeZone();
      result += "_";
      result += now.getTime();
      return result;
    }
}


returns this:




sun.util.calendar.ZoneInfo[id="Europe/Zurich",offset=3600000,dstSavings=3600000,useDaylight=true,transitions=119,lastRule=java.util.SimpleTimeZone[id=Europe/Zurich,offset=3600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]]_Wed Nov 07 22:45:56 CET 2012


I understand that there is a JVM property – Duser.timezone=’BLA’ 

or better still you can do
export TZ="IST"

on the shell prompt before you start WLS...




No comments: