Обсуждение: Date formats/time zones

Поиск
Список
Период
Сортировка

Date formats/time zones

От
elliotl@start-global.com
Дата:
Hello. I am using the JDBC2.0 driver (pgjdbc2.jar) along with PostgreSQL
7.2.1 in a Java web app running on Tomcat 4.0.4. I've also imported Sun's
rowset.jar file so I can use the CachedRowSet object. I use both the
ResultSet and CachedRowSet objects in my code, and assumed their functions
to be identical. However, I have found a small discrepancy, and while I
have dealt with the problem, I'm still curous as to its origins.
The issue is that I'm implementing time zone support, and was quite pleased
to find that adding a date to a query in the form '21 Aug 2002 00:44:33
BST' was automatically translated to GMT before adding it to the database.
However, getting it out has proved more tricky. I've long since abandoned
using rs.getDate() to retrieve dates since it doesn't retireve time
information (which seems like a major oversight to me - though admittedly
not on your part!). Now I use getString and parse the date myself. Here's
where it gets strange. When I use rs.getString, I get a string like:
"2002-08-20 23:07:34+00". When I use the CachedRowSet object's getString
method (which is JDBC2.0) I get: "2002-08-21 00:07:34.0", the difference
being (aside from the . instead of +) is that the second one has already
been corrected for British Summer Time (BST)!. I've gotten around it by
only providing my own time correction only if a "+" is found, but I would
very much appreciate some kind of explanation for why this is happening!

Thanks for your time!

-Elliot Long


Re: Date formats/time zones

От
Barry Lind
Дата:
The first question I would ask is why you are not using the
getTimestamp() method of the resultset?  You really don't want to be
parsing the postgres dateformat unless you have to.

thanks,
--Barry

elliotl@start-global.com wrote:

>Hello. I am using the JDBC2.0 driver (pgjdbc2.jar) along with PostgreSQL
>7.2.1 in a Java web app running on Tomcat 4.0.4. I've also imported Sun's
>rowset.jar file so I can use the CachedRowSet object. I use both the
>ResultSet and CachedRowSet objects in my code, and assumed their functions
>to be identical. However, I have found a small discrepancy, and while I
>have dealt with the problem, I'm still curous as to its origins.
>The issue is that I'm implementing time zone support, and was quite pleased
>to find that adding a date to a query in the form '21 Aug 2002 00:44:33
>BST' was automatically translated to GMT before adding it to the database.
>However, getting it out has proved more tricky. I've long since abandoned
>using rs.getDate() to retrieve dates since it doesn't retireve time
>information (which seems like a major oversight to me - though admittedly
>not on your part!). Now I use getString and parse the date myself. Here's
>where it gets strange. When I use rs.getString, I get a string like:
>"2002-08-20 23:07:34+00". When I use the CachedRowSet object's getString
>method (which is JDBC2.0) I get: "2002-08-21 00:07:34.0", the difference
>being (aside from the . instead of +) is that the second one has already
>been corrected for British Summer Time (BST)!. I've gotten around it by
>only providing my own time correction only if a "+" is found, but I would
>very much appreciate some kind of explanation for why this is happening!
>
>Thanks for your time!
>
>-Elliot Long
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 2: you can get off all lists at once with the unregister command
>    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>
>
>