【问题标题】:How to convert UTC Timestamp to Timestamp with time zone如何将 UTC 时间戳转换为带时区的时间戳
【发布时间】:2014-05-30 08:33:44
【问题描述】:

我正在使用 PostgreSql,并且有一个数据类型为 Timestamp 和时区的列。但是从服务器接收到“UTC Timestamp”值。我需要将其转换为“带时区的时间戳”,以便在需要时进行进一步比较。

我该怎么做。请建议我转换它然后存储的方法。

【问题讨论】:

  • 我不确定我是否理解。您希望将 UTC 时间戳转换为哪个时区? UTC (就计算机而言)已经是一个时区。
  • 我需要将 UTC 时间戳转换为“带时区的时间戳”。它是为我的表中的列分配的数据类型。

标签: sql postgresql datetime utc


【解决方案1】:

使用AT TIME ZONE operator 进行隐蔽

  • timestamps without time zones 到 timestamps with time zones
  • timestamps with time zones 到 timestamps without time zones

timestamps without time zone(又名timestamp)始终被视为采用 UTC。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-09
    • 2013-06-30
    • 1970-01-01
    • 2020-06-13
    • 2019-10-07
    • 2018-12-18
    • 1970-01-01
    • 2019-08-15
    相关资源
    最近更新 更多