Re: Having a hard time understanding time zone - Mailing list pgsql-jdbc

From Dave Cramer
Subject Re: Having a hard time understanding time zone
Date
Msg-id CADK3HHL_B+sM46LCBAs1c4MnKuFYKbgGOR5DHhK52-BXQfyqWg@mail.gmail.com
Whole thread Raw
In response to Having a hard time understanding time zone  (Robert DiFalco <robert.difalco@gmail.com>)
Responses Re: Having a hard time understanding time zone  (Robert DiFalco <robert.difalco@gmail.com>)
Re: Having a hard time understanding time zone  (Robert DiFalco <robert.difalco@gmail.com>)
List pgsql-jdbc
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!

pgsql-jdbc by date:

Previous
From: Robert DiFalco
Date:
Subject: Having a hard time understanding time zone
Next
From: David Johnston
Date:
Subject: Re: Having a hard time understanding time zone