PostgreSQL输出带时区的时间戳

时间:2014-01-06 20:01:46

标签: postgresql timezone timestamp

尝试在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'相同,为什么输出完全不同?

1 个答案:

答案 0 :(得分:0)

这是因为当你使用没有名字的时区时,PostgreSQL符合POSIX标准。

来自IANA Timezone database

# 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).

来自POSIX Spec as documented for GNU libc(强调我的):

  

偏移量指定 您必须添加到当地时间以获得协调世界时值的时间值。 它的语法类似于[+ | - ] hh [:毫米[:SS]]。如果当地时区在Prime Meridian以西,则为正,如果在东部,则为负。小时必须介于0到24之间,分钟和秒介于0到59之间。