postgresql – 为什么时区在Postgres的0001年具有如此疯狂的UTC偏移?

前端之家收集整理的这篇文章主要介绍了postgresql – 为什么时区在Postgres的0001年具有如此疯狂的UTC偏移?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在Postgres 9.5中,我很惊讶地看到下面的结果,同时试验了0001年(没有零年0000).

抵消-07:52:58?

一些示例代码.请注意,我混合使用TIMESTAMP WITH TIME ZONE和TIMESTAMP没有时区,所以请仔细阅读.

SET TIME ZONE 'America/Los_Angeles' ;

SELECT (TIMESTAMP WITH TIME ZONE '2015-01-01 00:00:00.0',TIMESTAMP WITH TIME ZONE '0001-01-01 00:00:00.0Z',TIMESTAMP WITHOUT TIME ZONE '0001-01-01 00:00:00.0Z') ;

("2015-01-01 00:00:00-08","0001-12-31 16:07:02-07:52:58 BC","0001-01-01 00:00:00")

我对第二个值感到惊讶:0001-12-31 16:07:02-07:52:58 BC.我知道我们必须向后退八小时,因为America / Los_Angeles比UTC低8小时,偏移为-08:00.但不是-08:00而是-07:52:58.为什么?

UTC下无问题

在UTC下输入数据时没有这样的问题.

SET TIME ZONE 'UTC' ;

SELECT (TIMESTAMP WITH TIME ZONE '2015-01-01 00:00:00.0',TIMESTAMP WITHOUT TIME ZONE '0001-01-01 00:00:00.0Z');

("2015-01-01 00:00:00+00","0001-01-01 00:00:00+00","0001-01-01 00:00:00")

没有零年

顺便说一句,日期部分似乎是正确的.似乎没有0000年,这是“BC”和“AD”时代之间的支点.在0001年的第一个时刻,减去一个小时,你得到公元前0001年 – 所以没有零年.

SET TIME ZONE 'UTC' ;

INSERT INTO moment_  -- TIMESTAMP WITH TIME ZONE.
VALUES ( TIMESTAMP '0001-01-01 00:00:00.0Z' - INTERVAL '1 hour' ) ;

SET TIME ZONE 'UTC' ;

TABLE moment_ ;

结果是公元前0001年,所以我们从0001跳到公元前0001年;没有一年零0000.

"0001-12-31 23:00:00+00 BC"
1883年11月18日中午12点(新时间),美国铁路采用标准时间.

这意味着在此之前,洛杉矶使用实际的当地时间,基于平均太阳时.之后,它被移动到当地时区,这是与格林威治标准时间相差几小时的积分,与前一时间略有不同.

想知道更多?

>从IANA: Time zones下载tzdata时区数据库.
>在里面,你会发现(很多)时区的定义,这些时区随着时间的推移会有很多变化,还有很多评论详细说明了改变的地点和时间.这是一个有趣的阅读!
>维基百科在Wikipedia: Time zone页面中也有一些有趣的事实,关于1883年11月18日的变化:

Railway time

Timekeeping on the American railroads in the mid-19th century was somewhat confused. Each railroad used its own standard time,usually based on the local time of its headquarters or most important terminus,and the railroad’s train schedules were published using its own time. Some junctions served by several railroads had a clock for each railroad,each showing a different time.
… Dowd’s system was never accepted by American railroads. Instead,U.S. and Canadian railroads implemented a version proposed by William F. Allen,the editor of the Traveler’s Official Railway Guide. The borders of its time zones ran through railroad stations,often in major cities. For example,the border between its Eastern and Central time zones ran through Detroit,Buffalo,Pittsburgh,Atlanta,and Charleston. It was inaugurated on Sunday,November 18,1883,also called “The Day of Two Noons”,when each railroad station clock was reset as standard-time noon was reached within each time zone. The zones were named Intercolonial,Eastern,Central,Mountain,and Pacific. …

另请注意,这不是Postgresql特有的.这适用于使用tzdata数据库的任何软件或操作系统(当然,许多将限制在1970年后或1901年后的日期,所以1883年是无法实现的,但是在所有地方还有许多其他调整不同时期).

原文链接:https://www.f2er.com/postgresql/192452.html

猜你在找的Postgre SQL相关文章