pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Jowett <oliver@opencloud.com>
To: Fred Janon <fjanon@gmail.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Issue with the JDBC driver doing timezone conversions on 	"java.sql.Date"?
Date: Mon, 21 Dec 2009 21:08:13 +1300
Message-ID: <4B2F2CED.10400@opencloud.com> (raw)
In-Reply-To: <2fd0c7810912202251t77ab60c7hac81d961761e5075@mail.gmail.com>
References: <2fd0c7810912202251t77ab60c7hac81d961761e5075@mail.gmail.com>

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



view thread (2+ messages)

Message-ID: <4B2F2CED.10400@opencloud.com>
Permalink:  ../4B2F2CED.10400@opencloud.com/
Also on:    postgresql.org/message-id/4B2F2CED.10400@opencloud.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: oliver@opencloud.com, fjanon@gmail.com
  Subject: Re: Issue with the JDBC driver doing timezone conversions on 	"java.sql.Date"?
  In-Reply-To: <4B2F2CED.10400@opencloud.com>
  References: <2fd0c7810912202251t77ab60c7hac81d961761e5075@mail.gmail.com> <4B2F2CED.10400@opencloud.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox