specify cqlsh output timezone

前端 未结 4 2054
一个人的身影
一个人的身影 2020-12-17 23:12

I have a table in cassandra with a datatype of timestamp. i am using cqlsh to get data out of the database and wanted to change the output format for how my timestamp column

相关标签:
4条回答
  • 2020-12-17 23:16

    Thanks for the question. Here is just an alternative way, which is do some date operation after you fetch the data using "datetime.timedelta()". You can calculate the offset time from UTC, and then do a date adjust. Just for your reference.

    >>> import datetime 
    >>> offset = -10 # in hours
    >>> original = '08/19/2015 10:59' 
    >>> adjusted = datetime.datetime.strptime(original, '%m/%d/%Y %H:%M') + datetime.timedelta(hours=offset) 
    >>> print adjusted.strftime('%m/%d/%Y %H:%M') 
        08/19/2015 00:59
    
    0 讨论(0)
  • 2020-12-17 23:23

    You can change your environment variable to get show timezone:

    TZ=America/Los_Angeles cqlsh -k mpj `hostname` -e 'select time from userbehavior limit 3'
    
     time
    --------------------------
     2015-02-15 21:17:03-0800
     2015-02-15 18:16:21-0800
     2015-02-15 00:04:52-0800
    
    (3 rows)
    

    and:

    TZ=UTC cqlsh -k mpj `hostname` -e 'select time from userbehavior limit 3'
    
     time
    --------------------------
     2015-02-16 05:17:03+0000
     2015-02-16 02:16:21+0000
     2015-02-15 08:04:52+0000
    
    (3 rows)
    
    0 讨论(0)
  • 2020-12-17 23:24

    The cqlshrc timeout option configures the output format of database objects using Python strftime syntax according to http://www.datastax.com/documentation/cql/3.1/cql/cql_reference/cqlsh.html. I haven't verified that these strftime directives work, but if you're willing to experiment try using the strftime() directive %z (UTC offset in the form +HHMM or -HHMM and %Z (time zone name). See https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior.

    0 讨论(0)
  • 2020-12-17 23:33

    You can change default timezone of local cqlsh by editing ~/.cassandra/cqlshrc

    Ex :

    [ui] TZ = IST

    0 讨论(0)
提交回复
热议问题