Re: How to make PostgreSQL JDBC drive get PGTZ?

From: Peter T Mount <peter(at)retep(dot)org(dot)uk>
To: Raymond Chui <raymond(dot)chui(at)noaa(dot)gov>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to make PostgreSQL JDBC drive get PGTZ?
Date: 2001-02-13 09:34:02
Message-ID: 982056842.3a88ff8aae2a5@webmail.retep.org.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-jdbc

Quoting Raymond Chui <raymond(dot)chui(at)noaa(dot)gov>:

>
> My system time zone (TZ) is set to US Eastern Standard Time is -5 hours
> of
> GMT time
>
> I set
> export PGTZ=GMT
> then go to psql do
>
> insert into a_table (a_column) values ('2001-02-08 18:30:00+00');
> select a_column from a_table;
>
> will get result exactly what I inserted
> 2001-02-08 18:30:00+00
>
> But when I used JDBC drive from org.postgresql.Driver to insert the
> same
> value,
> I got
>
> 2001-02-08 23:30:00+00
>
> This is the value of GMT time at 18:30 of EST time! Which tell me
> the Postgres JDBC drive insert the value in EST time. Why is that?

JDBC (& Java in general) works on a standard timezone so your local date is
converted into GMT (or rather UTC) when it's stored, so what you should use is
getDate() and then use a Calendar object (eg GregorianCalendar) to convert to
your local timezone.

7.1 has the extra methods that can pass a Calendar object implemented (not
fully tested yet, but will be in CVS by the weekend).

There are still a few date/time problems. I'm due in the next few evenings to
start writing the TestCases for Date/Time/Timestamp's so when they are done,
we'll have a firm base to work on (rather than guess work used so far).

>
> I already did
> Properties p = new Properties();
> p.put("PGTZ", "GMT");
> before connect to PostgreSQL server, but no luck!

The JDBC driver only accepts a few properties, and PGTZ isn't one of them, and
never will because Java uses it's own time zone handling.

I'd advise you read up on Calendar to see how timezones are handled.

Peter

--
Peter Mount peter(at)retep(dot)org(dot)uk
PostgreSQL JDBC Driver: http://www.retep.org.uk/postgres/
RetepPDF PDF library for Java: http://www.retep.org.uk/pdf/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Trewern, Ben 2001-02-13 09:34:59 RE: [GENERAL] Re: ALTER DROP COLUMN
Previous Message martin.chantler 2001-02-13 09:13:11 Re: Re: numeric type and odbc from access 2000

Browse pgsql-jdbc by date

  From Date Subject
Next Message Peter T Mount 2001-02-13 10:02:45 Re: [INTERFACES] jdbc fastpath error & Z error (URGENT NEED!!!)
Previous Message Jouni Ahto 2001-02-12 23:19:26 Re: [PHP-DEV] Re: Re: PostgreSQL and PHP persistent connections