【问题标题】:Don't understand PostgreSQL's time zone behaviour不了解 PostgreSQL 的时区行为
【发布时间】:2016-09-13 08:28:29
【问题描述】:

我的本​​地时区是PRC(中国),是UTC+8,但是

select (timestamp '2016-09-01 00:00:00' at time zone 'PRC') 
        -  (timestamp '2016-09-01 00:00:00' at time zone 'UTC');

返回-08:00:00。不应该是+08:00:00吗?

我的 PostgreSQL 版本是 9.5。

【问题讨论】:

    标签: postgresql timezone


    【解决方案1】:

    不,它在做正确的事情 - 但您必须了解at time zone 的含义,当您为其提供一个表达式没有作为左侧的时区。它基本上将其解释为指定时区中的时间戳

    所以'2016-09-01 00:00:00' at time zone 'PRC' 的意思是“中国 9 月 1 日午夜时分”——即 2016-08-31T16:00:00Z。

    '2016-09-01 00:00:00' at time zone 'UTC' 的意思是“UTC 时间 9 月 1 日午夜时分”——即 2016-09-01T00:00:00Z。

    所以你要求2016-08-31T16:00:00Z - 2016-09-01T00:00:00Z,确实是-8 小时。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-27
      • 1970-01-01
      • 2013-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多