tl;dr
String sql = "SELECT CURRENT_TIMESTAMP ;
…
OffsetDateTime odt = myResultSet.getObject( 1 , OffsetDateTime.class ) ;
Avoid depending on host OS or JVM for default time zone
I recommend you write all your code to explicitly state the desired/expected time zone. You need not depend on the JVM’s current default time zone. And be aware that the JVM’s current default time zone can change at any moment during runtime, with any code in any thread of any app calling TimeZone.setDefault
. Such a call affects all apps within that JVM immediately.
java.time
Some of the other Answers were correct, but are now outmoded. The terrible date-time classes bundled with the earliest versions of Java were flawed, written by people who did not understand the complexities and subtleties of date-time handling.
The legacy date-time classes have been supplanted by the java.time classes defined in JSR 310.
To represent a time zone, use ZoneId
. To represent an offset-from-UTC, use ZoneOffset
. An offset is merely a number of hour-minutes-seconds ahead or behind the prime meridian. A time zone is much more. A time zone is a history of the past, present, and future changes to the offset used by the people of a particular region.
I need to force any time related operations to GMT/UTC
For an offset of zero hours-minutes-seconds, use the constant ZoneOffset.UTC
.
Instant
To capture the current moment in UTC, use an Instant
. This class represent a moment in UTC, always in UTC by definition.
Instant instant = Instant.now() ;
ZonedDateTime
To see that same moment through the wall-clock time used by the people of a particular region, adjust into a time zone. Same moment, same point on the timeline, different wall-clock time.
ZoneId z = ZoneId.of( "Asia/Tokyo" ) ;
ZonedDateTime zdt = instant.atZone( z ) ;
Database
You mention a database.
To retrieve a moment from the database, your column should be of a data type akin to the SQL-standard TIMESTAMP WITH TIME ZONE
. Retrieve an object rather than a string. In JDBC 4.2 and later, we can exchange java.time objects with the database. The OffsetDateTime
is required by JDBC, while Instant
& ZonedDateTime
are optional.
OffsetDateTime odt = myResultSet.getObject( … , OffsetDateTime.class ) ;
In most databases and drivers, I would guess that you will get the moment as seen in UTC. But if not, you can adjust in either of two ways:
- Extract a
Instant
: odt.toInstant()
- Adjust from the given offset to an offset of zero: OffsetDateTime odtUtc = odt.withOffsetSameInstant( ZoneOffset.UTC ) ;`.

About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date
, Calendar
, & SimpleDateFormat
.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
You may exchange java.time objects directly with your database. Use a JDBC driver compliant with JDBC 4.2 or later. No need for strings, no need for java.sql.*
classes.
Where to obtain the java.time classes?