Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

kkk avatar image
kkk asked Erick Ramirez answered

How do I set the timezone in Cassandra to UTC+9 or KST?

I am using embedded Cassandra 3.11.7 with spring boot.

I want to set KST time which is UTC + 9 in Cassandra timezone.

It looks like kst time on the web screen, but

When inserting the actual Cassandra, it is stored as utc that is -9 hours longer than the current time, so it is not possible to get an accurate value when looking up the date.

So I'm looking for a way to set the Cassandra timezone.

I have a cassandra configuration and webFlux.

@Configuration
@EnableReactiveCassandraRepositories
@PropertySource(value = "file:${sf1.manager.path}/conf/cassandra.properties", ignoreResourceNotFound = true)
public class CassandraConfig extends AbstractReactiveCassandraConfiguration  {
  

Thanks in advance for the good answer.

cassandra
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered

Cassandra does not store timezone information. Date and time data types are encoded independent of the timezone of the server.

For example:

  • The CQL date type is a 32-bit integer representing the number of days since Unix epoch (January 1, 1970).
  • The CQL time type is a 64-bit signed integer representing the number of nanoseconds since midnight GMT.
  • The CQL timestamp type is a 64-bit signed integer representing the number of milliseconds Unix epoch at 00:00 GMT.

Clients are responsible for displaying the data in the format required. For example, when you retrieve data using cqlsh, the data is displayed in UTC by default. To display date/time in a different timezone, cqlsh needs to be configured with a different timezone.

In your case, you will need to do the formatting/conversion within your application when displaying the data. Cheers!

Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.