pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Robert DiFalco <robert.difalco@gmail.com>
To: Dave Cramer <pg@fastcrypt.com>
Cc: List <pgsql-jdbc@postgresql.org>
Subject: Re: Having a hard time understanding time zone
Date: Sun, 6 Apr 2014 15:37:56 -0700
Message-ID: <1E80E3BD-947B-4598-9587-60BDFEE1CF46@gmail.com> (raw)
In-Reply-To: <CADK3HHL_B+sM46LCBAs1c4MnKuFYKbgGOR5DHhK52-BXQfyqWg@mail.gmail.com>
References: <CAAXGW-yLEavhB-Asex8_KEutgEHH5zPMEksgOF0JPieQrTXrWA@mail.gmail.com>
	<CADK3HHL_B+sM46LCBAs1c4MnKuFYKbgGOR5DHhK52-BXQfyqWg@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>

Well I feel a little crazy. But this is what I see.  I have a timestamp without time zone column with a default value of current_timestamp.  In PSQL I can see this value yields a UTC value. But when I insert from JDBC (not setting that column) and then look at the value with PSQL I see a PDT value?!  That is my JVM zone. When I get back to the office on Monday I'll try to create a test case. 




Justin McCammon
Sent from my iPhone

> On Apr 6, 2014, at 1:45 PM, Dave Cramer <pg@fastcrypt.com> wrote:
> 
> Robert,
> 
> The driver certainly doesn't do anything to a statement like
> 
> insert into foo (datecol) values (now())
> 
> it does use the calendar of the vm to get the string representation.
> 
> Time, and date are two things not very well handled in java or JDBC. What is the exact column type and what does it store in the database
> 
> But to answer your question you can do:
> 
> 
> stmt.setTimestamp(1, t, Calendar.getInstance( TimeZone.getTimeZone("UTC")))
> 
> Dave Cramer
> 
> dave.cramer(at)credativ(dot)ca
> http://www.credativ.ca
> 
> 
>> On 6 April 2014 13:56, Robert DiFalco <robert.difalco@gmail.com> wrote:
>> Does the JDBC driver set the timezone to the origin timezone for each statement?
>> 
>> I have a date column in a table. My Postgres server is running in UTC. My java app is running in "America/Los_Angeles".
>> 
>> I would expect a DEFAULT column of NOW() to insert the current UTC time. While if I specify the time with new Date() from Java I would expect the Java timezone. 
>> 
>> But oddly both set the date field to the localized time in Java and not the UTC time.
>> 
>> This makes me think that the driver is somehow forcing the session timezone.
>> 
>> If so is there any way to make the driver communicate with the server in UTC?
>> 
>> Thanks!
> 

view thread (10+ messages)  latest in thread

Message-ID: <1E80E3BD-947B-4598-9587-60BDFEE1CF46@gmail.com>
Permalink:  ../1E80E3BD-947B-4598-9587-60BDFEE1CF46@gmail.com/
Also on:    postgresql.org/message-id/1E80E3BD-947B-4598-9587-60BDFEE1CF46@gmail.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: robert.difalco@gmail.com, pg@fastcrypt.com
  Subject: Re: Having a hard time understanding time zone
  In-Reply-To: <1E80E3BD-947B-4598-9587-60BDFEE1CF46@gmail.com>
  References: <CAAXGW-yLEavhB-Asex8_KEutgEHH5zPMEksgOF0JPieQrTXrWA@mail.gmail.com> <CADK3HHL_B+sM46LCBAs1c4MnKuFYKbgGOR5DHhK52-BXQfyqWg@mail.gmail.com> <1E80E3BD-947B-4598-9587-60BDFEE1CF46@gmail.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