PostgreSQL 输出时间戳与时区



试图在PostgreSQL中输出timestamp with time zone
我已经尝试了几个参数,前两个很好。

(1):

select time at time zone 'UTC' from sf where id='365498691097858048';

它输出:

2013-08-08 15:44:13

(2):

select time at time zone 'PDT' from sf where id='365498691097858048';

它输出

2013-08-08 08:44:13

但第三个让我感到困惑:

(3):

select time at time zone 'UTC-07' from sf where id='365498691097858048';
2013-08-08 22:44:13
"

UTC-07"与"PDT"相同,为什么输出完全不同?

发生这种情况是因为当您使用没有名称的时区时,PostgreSQL符合POSIX标准。

来自 IANA 时区数据库:

# Be consistent with POSIX TZ settings in the Zone names,
# even though this is the opposite of what many people expect.
# POSIX has positive signs west of Greenwich, but many people expect
# positive signs east of Greenwich.  For example, TZ='Etc/GMT+4' uses
# the abbreviation "-04" and corresponds to 4 hours behind UT
# (i.e. west of Greenwich) even though many people would expect it to
# mean 4 hours ahead of UT (i.e. east of Greenwich).

来自 GNU libc 记录的 POSIX 规范(强调我的):

偏移量指定必须添加到本地时间才能获得协调世界时值的时间值。它的语法类似于 [+|-]hh[:mm[:ss]]。如果本地时区位于本初子午线以西,则为正,如果为东,则为负。小时必须介于 0 和 24 之间,分钟和秒必须介于 0 和 59 之间。

最新更新