【问题标题】:Convert Current Timestamp UTC to CET将当前时间戳 UTC 转换为 CET
【发布时间】:2020-08-26 14:59:14
【问题描述】:

我正在尝试找到一种将 current_timestamp 转换为不同时区的方法。

Simba Athena 中的 current_timestamp 函数默认为我提供 UTC 时间戳。 我想在 CET 时区获得相同的时间戳。请注意,我想在我的查询中自动执行此转换。

我尝试了 convert_timezone('CET', current_timestamp) 函数,但在 AWS Athena 中无法识别

在更简单的工作中,我正在寻找 Presto 中 SQL Server 函数 GETUTCDATE() 的替代品,但我想获取 CET 时间戳。有什么建议吗?

【问题讨论】:

    标签: presto amazon-athena trino


    【解决方案1】:

    Trino(以前称为 Presto SQL)中的current_timestamp 根据当前会话时区返回一个timestamp with time zone 值。例如,如果客户端在America/Los_Angeles 时区:

    trino> select current_timestamp;
                        _col0
    ---------------------------------------------
     2020-08-26 09:14:43.259 America/Los_Angeles
    (1 row)
    

    您可以使用current_timezone()查看会话的当前时区:

    trino> select current_timezone();
            _col0
    ---------------------
     America/Los_Angeles
    (1 row)
    

    要将timestamp with time zone 转换为另一个时区,您可以使用AT TIME ZONE 语法:

    trino> select current_timestamp at time zone 'America/New_York';
                      _col0
    ------------------------------------------
     2020-08-26 12:18:37.901 America/New_York
    (1 row)
    

    【讨论】:

      猜你喜欢
      • 2020-08-18
      • 1970-01-01
      • 2017-06-11
      • 2019-08-15
      • 2015-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-27
      相关资源
      最近更新 更多