tl;dr
Never use the legacy class Date
.
Instant.now()
For current moment as seen in UTC.
ZonedDateTime.now( ZoneId.of( "Pacific/Honolulu" ) )
For current moment as seen in a particular time zone.
2020-02-18T05:28:11.146726Z
2020-02-17T19:28:11.146726-10:00[Pacific/Honolulu]
Details
Firstly, you should know that your java.util.Date
is actually a moment in UTC but its toString
method dynamically applies the JVM's current default time zone while generating the text. Very confusing. One of many reasons to never use this class.
Date
, Calendar
, and the other legacy date-time classes were supplanted by java.time years ago with the adoption of JSR 310.
Avoid depending on default time zone
Using the java.time classes, you can easily write code that does not depend on a default time zone. You can specify your desired offset-from-UTC or time zone explicitly, whether that be UTC itself (an offset of zero hours-minutes-seconds) or a time zone like Pacific/Honolulu
.
UTC
If you want to track a moment in UTC, use Instant
.
Instant instant = Instant.now() ;
The Instant::toString
method generates text in standard ISO 8601 format. The formats defined by this standard are designed for data exchange.
String output = instant.toString() ;
output: 2020-02-18T05:28:11.146726Z
The Z
on the end means UTC, and is pronounced “Zulu”.
Zoned
If you want to see that same moment by the wall-clock time used by the people in Hawaii, apply a ZoneId
to get a ZonedDateTime
.
Never use the 2-4 letter abbreviation such as HDT
or EST
or IST
as they are not true time zones, not standardized, and not even unique(!).
Specify a proper time zone name in the format of Continent/Region
, such as America/Montreal
, Africa/Casablanca
, or Pacific/Auckland
.
ZoneId z = ZoneId.of( "Pacific/Honolulu" ) ;
ZonedDateTime zdt = instant.atZone( z ) ;
The ZonedDateTime::toString
method wisely extends the ISO 8601 format by appending the name of the time zone is square brackets.
String output = zdt.toString() ;
See this code run live at IdeOne.com.
outputZdt: 2020-02-17T19:28:11.146726-10:00[Pacific/Honolulu]

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?