Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 3E41B633968 for ; Mon, 21 Dec 2009 04:19:00 -0400 (AST) 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 60458-03-5 for ; Mon, 21 Dec 2009 08:18:52 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from tremor.opencloud.co.nz (tremor.opencloud.co.nz [131.203.101.230]) by mail.postgresql.org (Postfix) with ESMTP id D939B633C7C for ; Mon, 21 Dec 2009 04:08:17 -0400 (AST) Received: from 122-57-40-95.jetstream.xtra.co.nz ([122.57.40.95] helo=[192.168.1.3]) by tremor.opencloud.co.nz with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1NMdJN-0000F6-Mj; Mon, 21 Dec 2009 21:08:13 +1300 Message-ID: <4B2F2CED.10400@opencloud.com> Date: Mon, 21 Dec 2009 21:08:13 +1300 From: Oliver Jowett User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: Fred Janon CC: pgsql-jdbc@postgresql.org Subject: Re: Issue with the JDBC driver doing timezone conversions on "java.sql.Date"? References: <2fd0c7810912202251t77ab60c7hac81d961761e5075@mail.gmail.com> In-Reply-To: <2fd0c7810912202251t77ab60c7hac81d961761e5075@mail.gmail.com> X-Enigmail-Version: 0.95.7 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200912/74 X-Sequence-Number: 20155 Fred Janon wrote: > When I check the dates in the database using PGAdmin III on the client, > I see the dates in the client timezone (GTM +8). > If I do a > TimeZone.setDefault(TimeZone.getTimeZone("GMT")) > in my application, I see the dates with the "correct" (or expected) GMT > timezone. > > I don't understand why there is any timezone involved in reading and > writing "timestamp without time zone". Because "timestamp without time zone" is a little counterintuitive. It represents a particular wallclock date/time; it does not represent a unique instant in time. It's roughly like storing the string "2009-12-21 21:00:00" - that time interpreted in my timezone is right now, but it'll be some different instant when interpreted in your timezone. So when the JDBC driver needs to convert between a Java Timestamp - which *does* represent a particular instant in time, in terms of milliseconds-since-the-epoch - and a timestamp-without-timezone, it has to pick a particular timezone to do that. The driver follows the JDBC spec and uses the JVM's default timezone unless you explictly provide a Calendar to use when calling getTimestamp()/setTimestamp(). If you're trying to store particular instants-in-time, you probably want to use TIMESTAMP WITH TIME ZONE (which, again a little counterintuitively, does NOT actually store a timezone - it just stores milliseconds-since-the-epoch and converts that to/from different timezones on demand) -O