Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WWvhW-0005xj-Fn for pgsql-jdbc@arkaria.postgresql.org; Sun, 06 Apr 2014 22:38:06 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WWvhV-0006r7-MX for pgsql-jdbc@arkaria.postgresql.org; Sun, 06 Apr 2014 22:38:05 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WWvhT-0006qy-JE for pgsql-jdbc@postgresql.org; Sun, 06 Apr 2014 22:38:03 +0000 Received: from mail-pb0-x232.google.com ([2607:f8b0:400e:c01::232]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WWvhP-0005Cv-Js for pgsql-jdbc@postgresql.org; Sun, 06 Apr 2014 22:38:02 +0000 Received: by mail-pb0-f50.google.com with SMTP id md12so5894888pbc.9 for ; Sun, 06 Apr 2014 15:37:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=wdH3vPrH60JSlLW1X6Gxu/771kcRJWkRAK0V5xfD3Do=; b=QSM/2DgY2zxaBqLQCmG9AkypDzAOxKmzKSe+VNwXz6lrm7uhB8R4u3ZFdsmZMA9fcV z9tMEu9OxP0Nw4P6kufBf8BSlTlUViLn3hEip+8Cd2+c2UAikJW5/U8OQr1BBPlZjNNB zkGeAjuNmNNbnJGhg3VQKvtPxSvZLAuY67PUgLLdBpa/d3AIlZR6maIbDMStkB3OC7MP AxSGRTL7REJ7LW9KzxJ+tcM4KsCZ1UT0s4ZPqS35OGlSc+sBgmiMcG0NUSznGQEhb3h0 Ue9uSa+4Sj2MHZBlv042vYTEv43UZaT/PmQ4fdyOZZPnpWK3+95OZRDI2prs1KJTaTdR kP/Q== X-Received: by 10.68.222.105 with SMTP id ql9mr27628748pbc.4.1396823878376; Sun, 06 Apr 2014 15:37:58 -0700 (PDT) Received: from [192.168.0.41] (static-76-14-252-131.or.wavecable.com. [76.14.252.131]) by mx.google.com with ESMTPSA id pq3sm32353580pbb.57.2014.04.06.15.37.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 06 Apr 2014 15:37:57 -0700 (PDT) Content-Type: multipart/alternative; boundary=Apple-Mail-8466FC60-856F-46F5-B4AB-468C2E648911 Mime-Version: 1.0 (1.0) Subject: Re: Having a hard time understanding time zone From: Robert DiFalco X-Mailer: iPhone Mail (11D167) In-Reply-To: Date: Sun, 6 Apr 2014 15:37:56 -0700 Cc: List Content-Transfer-Encoding: 7bit Message-Id: <1E80E3BD-947B-4598-9587-60BDFEE1CF46@gmail.com> References: To: Dave Cramer X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org --Apple-Mail-8466FC60-856F-46F5-B4AB-468C2E648911 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Well I feel a little crazy. But this is what I see. I have a timestamp with= out time zone column with a default value of current_timestamp. In PSQL I c= an see this value yields a UTC value. But when I insert from JDBC (not setti= ng that column) and then look at the value with PSQL I see a PDT value?! Th= at is my JVM zone. When I get back to the office on Monday I'll try to creat= e a test case.=20 Justin McCammon Sent from my iPhone > On Apr 6, 2014, at 1:45 PM, Dave Cramer wrote: >=20 > Robert, >=20 > The driver certainly doesn't do anything to a statement like >=20 > insert into foo (datecol) values (now()) >=20 > it does use the calendar of the vm to get the string representation. >=20 > Time, and date are two things not very well handled in java or JDBC. What i= s the exact column type and what does it store in the database >=20 > But to answer your question you can do: >=20 >=20 > stmt.setTimestamp(1, t, Calendar.getInstance( TimeZone.getTimeZone("UTC"))= ) >=20 > Dave Cramer >=20 > dave.cramer(at)credativ(dot)ca > http://www.credativ.ca >=20 >=20 >> On 6 April 2014 13:56, Robert DiFalco wrote: >> Does the JDBC driver set the timezone to the origin timezone for each sta= tement? >>=20 >> I have a date column in a table. My Postgres server is running in UTC. My= java app is running in "America/Los_Angeles". >>=20 >> I would expect a DEFAULT column of NOW() to insert the current UTC time. W= hile if I specify the time with new Date() from Java I would expect the Java= timezone.=20 >>=20 >> But oddly both set the date field to the localized time in Java and not t= he UTC time. >>=20 >> This makes me think that the driver is somehow forcing the session timezo= ne. >>=20 >> If so is there any way to make the driver communicate with the server in U= TC? >>=20 >> Thanks! >=20 --Apple-Mail-8466FC60-856F-46F5-B4AB-468C2E648911 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
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_timestam= p.  In PSQL I can see this value yields a UTC value. But when I insert f= rom JDBC (not setting that column) and then look at the value with PSQL I se= e a PDT value?!  That is my JVM zone. When I get back to the office on M= onday I'll try to create a test case. 




Justin McCammon

On Apr 6, 2014, at 1:45 PM, Dave Cramer <pg@fastcrypt.com> wrote:

Rober= t,

The driver certainly doesn't do anything to a statemen= t like

insert into foo (datecol) values (now())

it does use the calendar of the vm to get the string r= epresentation.

Time, and date are two things not very well handled in j= ava or JDBC. What is the exact column type and what does it store in the dat= abase

But to answer your question you can do:
=

stmt.setTimestamp(1,=
.getInstance( T=
imeZone.getTimeZone("UTC")))

Dave Cramer

d= ave.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 timezon= e 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_A= ngeles".

I would expect a DEFAULT column of NOW() to insert the c= urrent UTC time. While if I specify the time with new Date() from Java I wou= ld expect the Java timezone. 

But oddly both s= et the date field to the localized time in Java and not the UTC time.

This makes me think that the driver is somehow forcing t= he session timezone.

If so is there any way to make= the driver communicate with the server in UTC?

Thanks!

= --Apple-Mail-8466FC60-856F-46F5-B4AB-468C2E648911--