X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 24FF4D7BF1 for ; Fri, 9 Sep 2005 08:18:34 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 51613-09 for ; Fri, 9 Sep 2005 11:18:30 +0000 (GMT) Received: from mail.humboldt.co.uk (mail.humboldt.co.uk [81.2.65.18]) by svr1.postgresql.org (Postfix) with ESMTP id 97431D7814 for ; Fri, 9 Sep 2005 08:18:30 -0300 (ADT) Received: from newt.humboldt.co.uk ([81.2.65.19] helo=[192.168.78.155]) by mail.humboldt.co.uk with asmtp (Exim 3.35 #1 (Debian)) id 1EDgts-0000Rt-00 for ; Fri, 09 Sep 2005 12:18:32 +0100 Subject: Two millisecond timestamp offset From: Adrian Cox To: pgsql-jdbc@postgresql.org Content-Type: text/plain Date: Fri, 09 Sep 2005 12:18:30 +0100 Message-Id: <1126264710.3069.76.camel@localhost> Mime-Version: 1.0 X-Mailer: Evolution 2.2.2 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 required=5 tests=[none] X-Spam-Level: X-Archive-Number: 200509/28 X-Sequence-Number: 13813 I couldn't find anything on this with Google, but I've got a 2ms offset between the java.sql.Timestamp representation and the string representation of a "timestamp with time zone". I've tried the following JDBC releases: 8.1dev-401 JDBC 3, 8.0-312 JDBC 3, pg74.216.jdbc3.jar. The server is the Debian package of 7.4.7, though I've seen the same problem against Postgres 7.2. Here's a section from my JAVA code: DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); format.setCalendar(new GregorianCalendar(ServletBase.UTC)); PreparedStatement stmt = db.prepareStatement("insert into test values(1,?)"); //create a statement that we can use later Date date = format.parse("2005-05-12 17:14:21"); stmt.setTimestamp(1, new Timestamp(date.getTime())); stmt.execute(); stmt = db.prepareStatement("select index, datetime from test"); Statement stmt2 = db.createStatement(); stmt2.executeUpdate("insert into test values(2, '2004-11-10 17:32:19')"); ResultSet rs = stmt.executeQuery(); DateFormat output = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); output.setCalendar(new GregorianCalendar(ServletBase.UTC)); while(rs.next()) { date = new Date(rs.getTimestamp(2).getTime()); System.out.println("Result " + rs.getInt(1) + " :- " + output.format(date)); } The output from Java code is: Result 1 :- 2005-05-12 17:14:21.000 Result 2 :- 2004-11-10 17:32:19.002 The database sees: testcode=> select * from test; index | datetime -------+---------------------------- 1 | 2005-05-12 17:14:20.998+00 2 | 2004-11-10 17:32:19+00 (2 rows) -- Adrian Cox