简体   繁体   中英

PostgreSQL output timestamp with time zone

Trying to output a timestamp with time zone in the PostgreSQL.
I have tried several params, the first two are fine.

(1):

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

it outputs:

2013-08-08 15:44:13

(2):

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

it outputs

2013-08-08 08:44:13

But the third one confuses me:

(3):

select time at time zone  from sf where id='365498691097858048';
2013-08-08 

'UTC-07' is the same as 'PDT', why the outputs are totally different?

This happens because PostgreSQL is being compliant with the POSIX standard when you use timezones without names.

From the 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 # (ie west of Greenwich) even though many people would expect it to # mean 4 hours ahead of UT (ie east of Greenwich). 

From the POSIX Spec as documented for GNU libc (emphasis mine):

The offset specifies the time value you must add to the local time to get a Coordinated Universal Time value. It has syntax like [+|-]hh[:mm[:ss]]. This is positive if the local time zone is west of the Prime Meridian and negative if it is east. The hour must be between 0 and 24, and the minute and seconds between 0 and 59.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM