Re: ResultSet.getTimestamp(Calendar) off by one-hour

From: Roland Roberts <roland(at)astrofoto(dot)org>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: ResultSet.getTimestamp(Calendar) off by one-hour
Date: 2009-03-13 20:46:58
Message-ID: 49BAC642.6090800@astrofoto.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Roland Roberts wrote:
> Roland Roberts wrote:
>> Okay, postgresql appears to be using the standard TZ offset
>> regardless of whether or not DST is in effect on the day in question.
> Hmmm, I *can* get the correct behavior IF I assign the environment
> variable TZ=America/New_York before I run the client program. But I
> don't need to do that when I'm talking to Oracle. For the Oracle
> case, the database is on another host, both still in US/Eastern time
> zone.
>
> Are there other ways to get PostgreSQL JDBC to understand the client
> timezone w/o explicitly setting TZ? I'm trying to find an idiot-proof
> (well, I'll settle for an idiot-resistant) method.
Blah. It looks like this is actually a known Java bug,
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6456628

Although the bug was posted in August 2006(!) against Java 1.5, the most
recent comment is from Aug 2008 still complaining that it is not fixed.
I don't know how Java comes up with the GMT-05:00, but changing
/etc/sysconfig/clock from ZONE="America/New York" to
ZONE="America/New_York" (Java naming convention with the underscore) is
sufficient to get everything to work although when I now include

System.out.println("default TZ=" +
TimeZone.getDefault().getDisplayName());

in my code, it prints

default TZ=Eastern Standard Time

which is a lie, its Eastern Daylight Time. In spite of that, the
correct value is inserted into PostgreSQL.

roland

--
PGP Key ID: 66 BC 3B CD
Roland B. Roberts, PhD RL Enterprises
roland(at)rlenter(dot)com 6818 Madeline Court
roland(at)astrofoto(dot)org Brooklyn, NY 11220

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Tom Lane 2009-03-13 21:50:10 Re: ResultSet.getTimestamp(Calendar) off by one-hour
Previous Message Roland Roberts 2009-03-13 20:31:40 Re: ResultSet.getTimestamp(Calendar) off by one-hour