Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 7F7126322BD for ; Sun, 13 Sep 2009 17:36:33 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 56585-04 for ; Sun, 13 Sep 2009 20:36:25 +0000 (UTC) X-Greylist: delayed 00:05:05.790591 by SQLgrey-1.7.6 Received: from mail.abstraxion.de (unknown [77.37.21.42]) by mail.postgresql.org (Postfix) with ESMTP id 8A08A632187 for ; Sun, 13 Sep 2009 17:36:25 -0300 (ADT) Received: from webmail.axn-software.de (localhost [::ffff:127.0.0.1]) by vs1404 with esmtp; Sun, 13 Sep 2009 22:31:11 +0200 id 000280C6.4AAD568F.0000037D Received: from 85.180.96.205 (SquirrelMail authenticated user carsten.klein@axn-software.de) by webmail.axn-software.de with HTTP; Sun, 13 Sep 2009 22:31:11 +0200 (CEST) Message-ID: <6a89dba438112783b27f59f66336472f.squirrel@webmail.axn-software.de> Date: Sun, 13 Sep 2009 22:31:11 +0200 (CEST) Subject: TimeZone related issues in org.postgresql.jdbc2.TimestampUtils From: "Carsten Klein" To: pgsql-jdbc@postgresql.org Reply-To: carsten.klein@axn-software.de User-Agent: SquirrelMail/1.4.15 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.085 tagged_above=-10 required=5 tests=BAYES_40=-0.185, RDNS_NONE=0.1 X-Spam-Level: X-Archive-Number: 200909/15 X-Sequence-Number: 19962 Hi All, in an application that uses TIMESTAMP WITH TIME ZONE as the type for certain attributes, we stumbled across the problem that, sometimes, the values returned from the database will be adjusted so that the time zone offset will be added/subtracted from the actual time stored in the database. Example: "2009-09-11 15:00:00+02" will be returned by TimestampUtils as "2009-09-11 13:00:00". This is due to the fact that in TimestampUtils.toTimestamp(...) and TimestampUtils.toTime(...) the following will be used for returning the Time or Timestamp instances, respectively: toTimestamp(): Timestamp result = new Timestamp(useCal.getTime().getTime()); toTime(): Time result = new Time(useCal.getTime().getTime()); This however, leads to the aforementioned, incorrect results, since the Calendar implementation, on getTime() will now adjust the initially correct date and time based on the time zone information that is stored with the data. Whilst trying to work around that problem, I found out, that it would be best to use toTimestamp(): DateFormat df = DateFormat.getDateTimeInstance(); df.setTimeZone( useCal.getTimeZone() ); Timestamp result = new Timestamp( df.parse( df.format( useCal.getTime() ) ).getTime() ); toTime(): DateFormat df = DateFormat.getTimeInstance(); df.setTimeZone( useCal.getTimeZone() ); Time result = new Time( df.parse( df.format( useCal.getTime() ) ).getTime() ); This then will lead to the correct results. TIA for fixing this! Best Regards Carsten Klein -- axn software UG (haftungsbeschränkt) Wipperfürther Str. 278 51515 Kürten HRB 66732 Gerichtsstand Amtsgericht Bergisch Gladbach Telefon +492 268 801 285 Telefax +492 268 801 285 Mobil +491 577 666 256 5 WWW http://www.axn-software.de Email info@axn-software.de