I\'ve run into an interesting challenge using a PostgreSQL database with the PostgreSQL JDBC driver. It seems that the latest version of the driver, 9.2, uses the client
Short version try:
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
Hi we ran across this issue with client and server timezone miss match We needed our unit tests to be run using "UTC". By looking at the source code for postgres jdbc driver (and this being test code) we "fixed" it by changing the TZ inside of the jvm before obtaining a connection.
I don’t know JasperReports, but generally speaking, using the JSR-310 (Java 8) date/time types (supported by JDBC 4.2) should work without having to worry about time zone mismatches between database server and client.
See Using Java 8 Date and Time classes in the PostgreSQL JDBC driver documentation.
I just ran into this issue myself. I verified that the postgres jdbc driver is indeed picking up the connection timezone from the jvm, and I wasn't able to find a way to override this behavior. It really would be nice if they provided a jdbc url connection parameter for this purpose.
As a workaround, I discovered that my connection pool library (HikariCP) can execute a sql statement for each new connection:
hikariConfig.setConnectionInitSql("set time zone 'UTC'");
The use of the local timezone as the default timezone is required by the JDBC standard (and API documentation), and is made explicit by PreparedStatement.setTimestamp. However it also applies to all other areas where JDBC sets or retrieves time related data.
See also my answer to Is java.sql.Timestamp timezone specific?
Just in case others struggle with this - you can edit the "conf" file that launches SQLDeveloper and add the following line :
AddVMOption -Duser.timezone=UTC
I found this file on my machine at :
/opt/sqldeveloper/ide/bin/ide.conf
Thanks to @a_horse_with_no_name for pointing me in the right direction with a comment in one of the other answers