Re: How to make PostgreSQL JDBC drive get PGTZ?

Поиск
Список
Период
Сортировка
От Peter T Mount
Тема Re: How to make PostgreSQL JDBC drive get PGTZ?
Дата
Msg-id 982056842.3a88ff8aae2a5@webmail.retep.org.uk
обсуждение исходный текст
Ответ на How to make PostgreSQL JDBC drive get PGTZ?  (Raymond Chui <raymond.chui@noaa.gov>)
Список pgsql-general
Quoting Raymond Chui <raymond.chui@noaa.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@retep.org.uk
PostgreSQL JDBC Driver: http://www.retep.org.uk/postgres/
RetepPDF PDF library for Java: http://www.retep.org.uk/pdf/

В списке pgsql-general по дате отправления:

Предыдущее
От: martin.chantler@convergys.com
Дата:
Сообщение: Re: Re: numeric type and odbc from access 2000
Следующее
От: "Trewern, Ben"
Дата:
Сообщение: RE: Re: ALTER DROP COLUMN