【问题标题】:Converting time to 12 hour format in Cassandra在 Cassandra 中将时间转换为 12 小时格式
【发布时间】:2018-12-13 23:51:22
【问题描述】:

我正在使用 Cassandra 3.11.2。 Cassandra 以 24 小时格式显示日期和时间。如何将其更改为标准 12 小时格式?

【问题讨论】:

    标签: cassandra cqlsh


    【解决方案1】:

    cqlsh 中时间的打印由~/.cassandra/cqlshrc[ui] 部分中的time_format 设置控制。格式字符串对应于 Python 的 time.strftime format。所以你需要改成这样的东西(%I - 12 小时格式,%p - AM/PM 指标):

    [ui]
    time_format = %Y-%m-%d %I:%M:%S %p 
    

    例子:

    cqlsh> create table test.tm(id int primary key, tm timestamp);
    cqlsh> insert into test.tm(id,tm) values(1, '2018-06-18 18:30:55Z');
    cqlsh> SELECT * from test.tm;
    
     id | tm
    ----+------------------------
      1 | 2018-06-18 08:30:55 PM    
    
    (1 rows)
    

    【讨论】:

    • 嗨,Alex,它不适合我。我已经完成了 cqlshrc 文件的更改,并将其放在主目录中的 .cassandra 中。为了确认这一点,我更改了反映但 12 小时格式没有反映的时区。
    • //这是我的更改// datetimeformat = %Y-%m-%d %I:%M:%S %p %z timezone = Asia/Kolkata
    • 我已经添加了我的输出示例...datetimeformat 应该由COPY FROM/TO 命令使用,而不是SELECT 的输出
    • 什么版本的 Cassandra?在旧版本中,cqlshrc 的示例中存在错误 - 他们使用 datettimeformat 而不是正确的 time_format: issues.apache.org/jira/browse/CASSANDRA-14243
    • 好人,它奏效了。我添加了 time_format 而不是 datetimeformat。我正在使用最新版本的 Cassandra 3.11.2。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-17
    • 1970-01-01
    • 1970-01-01
    • 2022-11-30
    • 2017-02-13
    • 2019-12-24
    相关资源
    最近更新 更多