I would like to save the timestamp in the database without converting to the local timezone using the jdbc driver. Currently, only MySQL and PostgreSQL are important to me, but I would appreciate it if there was a database independent solution.
Example:
// i want that to be saved as 1970-01-01 00:00:00 TimeStamp ts = new java.sql.Timestamp(0); // gets transformed to local time by jdbc driver (in my case to 1970-01-01 01:00:00) st.setTimestamp(0, new java.sql.Timestamp(0)); // only works using postgres (mysql connector seems to ignore the calendar) // postgres => 1970-01-01 00:00:00 // mysql => 1970-01-01 01:00:0 Calendar calutc = Calendar.getInstance(TimeZone.getTimeZone("UTC")); st.setTimestamp(0, new java.sql.Timestamp(0), utccal);
I have already tried to calculate the timestamp value, which will be converted to the correct value (for example, -3600000 => 1970-01-01 00:00:00 in my time zone), but this does not work on postgres in the dates the time saving changes during the day .
source share