pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Cox <adrian@humboldt.co.uk>
To: pgsql-jdbc@postgresql.org
Subject: Two millisecond timestamp offset
Date: Fri, 09 Sep 2005 12:18:30 +0100
Message-ID: <1126264710.3069.76.camel@localhost> (raw)

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 <adrian@humboldt.co.uk>




view thread (4+ messages)  latest in thread

Message-ID: <1126264710.3069.76.camel@localhost>
Permalink:  ../1126264710.3069.76.camel@localhost/
Also on:    postgresql.org/message-id/1126264710.3069.76.camel@localhost

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: adrian@humboldt.co.uk
  Subject: Re: Two millisecond timestamp offset
  In-Reply-To: <1126264710.3069.76.camel@localhost>
  References: <1126264710.3069.76.camel@localhost>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox