Caveat: I’m not a Cassandra user.
According to the documentation, Cassandra stores time stamps in UTC.
There should be no need to set the default time zone of the Cassandra server or its JVM. Simply exchange values in UTC, having an offset of zero hours-minutes-seconds. Use the java.time classes only, never the terrible legacy classes.
Capture the current moment in UTC.
Instant instant = Instant.now() ;
Generate text in standard ISO 8601 format. The Z
on the end means an offset of zero hours-minutes-seconds from UTC, and is pronounced “Zulu”.
String s = instant.toString() ;
Parse such a string.
Instant instant = Instant.parse( s ) ;
If using JDBC, convert to the OffsetDateTime
class.
OffsetDateTime odt = instant.atOffset( ZoneOffset.UTC ) ;
myPreparedStatement.setObject( … , odt ) ;
Retrieval.
OffsetDateTime odt = myResultSet.getObject( … , OffsetDateTime.class ) ;
Adjust into a time zone to view that moment in the wall-clock time of your region.
The 2-4 letter codes such as KST
, CST
, IST
are not actual time zones. They hint at the time zone, and indicate if Daylight Savings Time (DST) is in effect or not. These pseudo-zones are not standardized, and are not unique! Use these only for localized presentation to the user, never for data storage nor data exchange.
Real time zones are named in format of Continent/Region
such as Asia/Seoul
.
ZoneId z = ZoneId.of( "Asia/Seoul" ) ;
ZonedDateTime zdt = odt.atZoneSameInstant( z ) ;
Generate strings, automatically localized using DateTimeFormatter.ofLocalizedDateTime
.