'Timezone in Cassandra DB
I am unable to store timestamp in cassandra in the local timezone. My springdata API receives the data from a flat file (populated from a UNIX server). The data is converted into java.util.Date and persisted into a cassandra table on timestamp data type.
But it always gets converted to GMT
String str_data = "13/05/2019 15:38:08";
DateFormat format = new SimpleDateFormat("d/M/yyyy H:m:s", Locale.ENGLISH);
Date timestamp = format.parse(str_data);
format.setTimeZone(TimeZone.getTimeZone("Europe/London"));
System.out.println("Time: "+timestamp);
The output on my java console is correct as below:
Time: Mon May 13 15:38:08 BST 2019
But Cassandra DB is as:
ts
--------------------------------
2019-05-13 14:38:08.000000+0000
What am I doing wrong please?
Version Info: [cqlsh 5.0.1 | Cassandra 3.11.2 | CQL spec 3.4.4 | Native protocol v4]
Solution 1:[1]
Timestamps are always stored converted to GMT, and then it's your application responsibility to convert it into correct representation. Internally the timestamp is stored as long number, and converted when displaying.
If you want to get this data formatted correctly in cqlsh
, you need to setup your ~/.cassandra/cqlshrc
file with time zone information - it's done via timezone
configuration parameter, like this:
[ui]
TZ = Europe/London
or setting the TZ
environment variable when starting cqlsh
.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Matt Johnson-Pint |