Postgres UTC date format & epoch cast, sign inversion

前端 未结 1 1625
后悔当初
后悔当初 2020-12-11 08:35

Could someone explain me this sign inversion, i\'m lost here...

SELECT EXTRACT(EPOCH FROM \'01-01-1970 00:00:00 UTC+01\'::timestamp with time zone)


        
相关标签:
1条回答
  • 2020-12-11 08:53

    This

    1970-01-01 00:00:00+01
    

    is an ISO 8601 timestamp with a +1 hour offset and +1 means east of Greenwich. The offsets in these

    01-01-1970 00:00:00 UTC+01
    1970-01-01 00:00:00 UTC+01
    1970-01-01 00:00:00 XXX+01
    1970-01-01 00:00:00 HAHA+01
    1970-01-01 00:00:00 Pancakes+01
    

    will be interpreted as POSIX style timezones where +1 means west of Greenwich:

    PostgreSQL will accept POSIX-style time zone specifications of the form STDoffset or STDoffsetDST, where STD is a zone abbreviation, offset is a numeric offset in hours west from UTC

    and those even come with a warning:

    One should be wary that the POSIX-style time zone feature can lead to silently accepting bogus input, since there is no check on the reasonableness of the zone abbreviations. For example, SET TIMEZONE TO FOOBAR0 will work, leaving the system effectively using a rather peculiar abbreviation for UTC. Another issue to keep in mind is that in POSIX time zone names, positive offsets are used for locations west of Greenwich. Everywhere else, PostgreSQL follows the ISO-8601 convention that positive timezone offsets are east of Greenwich.

    Note the west versus east difference.

    0 讨论(0)
提交回复
热议问题