TimeZone related issues in org.postgresql.jdbc2.TimestampUtils

Поиск
Список
Период
Сортировка
От Carsten Klein
Тема TimeZone related issues in org.postgresql.jdbc2.TimestampUtils
Дата
Msg-id 6a89dba438112783b27f59f66336472f.squirrel@webmail.axn-software.de
обсуждение исходный текст
Ответы Re: TimeZone related issues in org.postgresql.jdbc2.TimestampUtils  (Oliver Jowett <oliver@opencloud.com>)
Список pgsql-jdbc
Hi All,

in an application that uses TIMESTAMP WITH TIME ZONE as the type for
certain attributes, we stumbled across the problem that, sometimes, the
values returned from the database will be adjusted so that the time zone
offset will be added/subtracted from the actual time stored in the
database.

Example: "2009-09-11 15:00:00+02" will be returned by TimestampUtils as
"2009-09-11 13:00:00".

This is due to the fact that in TimestampUtils.toTimestamp(...) and
TimestampUtils.toTime(...) the following will be used for returning the
Time or Timestamp instances, respectively:


toTimestamp(): Timestamp result = new Timestamp(useCal.getTime().getTime());

toTime():  Time result = new Time(useCal.getTime().getTime());

This however, leads to the aforementioned, incorrect results, since the
Calendar implementation, on getTime() will now adjust the initially
correct date and time based on the time zone information that is stored
with the data.

Whilst trying to work around that problem, I found out, that it would be
best to use

toTimestamp():
  DateFormat df = DateFormat.getDateTimeInstance();
  df.setTimeZone( useCal.getTimeZone() );
  Timestamp result = new Timestamp( df.parse( df.format( useCal.getTime()
) ).getTime() );

toTime():
  DateFormat df = DateFormat.getTimeInstance();
  df.setTimeZone( useCal.getTimeZone() );
  Time result = new Time( df.parse( df.format( useCal.getTime() )
).getTime() );

This then will lead to the correct results.

TIA for fixing this!

Best Regards

Carsten Klein


--

axn software UG (haftungsbeschränkt)
Wipperfürther Str. 278
51515 Kürten

HRB 66732
Gerichtsstand Amtsgericht Bergisch Gladbach

Telefon +492 268 801 285
Telefax +492 268 801 285
Mobil   +491 577 666 256 5

WWW http://www.axn-software.de
Email info@axn-software.de



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

Предыдущее
От: Thomas Kellerer
Дата:
Сообщение: Re: Need help to download jdbc driver in Dspace windows
Следующее
От: Oliver Jowett
Дата:
Сообщение: Re: TimeZone related issues in org.postgresql.jdbc2.TimestampUtils