Hi all,
I have some code inserting a timestamp in a Postgres table. Here is the definition of the field where the timestamp is inserted:
datelast timestamp without time zone
I use this Java code to update data in the field:
PreparedStatement sqlStatement = connection.prepareStatement(
"UPDATE datetest SET datelast = ? WHERE id = ? ");
sqlStatement.setTimestamp(1, new java.sql.Timestamp((new Date()).getTime()));
sqlStatement.setInt(2, 1);
sqlStatement.executeUpdate();
My problem is that it inserts the UTC timestamp instead of my local timestamp (eastern time). So when I check the data in my table, I see "2010-02-08 19:07:21.261" instead of "2010-02-08 14:07:21.261".
Actually, I had this code running has I would like to on an old server, but after migrating the code, I got that problem. The problem is not whit Postgres because I still use the same DB. I also checked the OS timezone and they are the same. I also tried a "System.out.println("TZ = " + TimeZone.getDefault());" and I get the same timezone on both servers. So my conclusion is that the JDBC driver is converting the date in UTC before inserting it in the table.
Can anyone help me to figure out why the timestamp is converted?
Thanks