我在Postgres有一张桌子(13.3):
create table owner (date_time timestamp with time zone);我保存了一张时区记录:
insert into owner(date_time) values (timestamp with time zone '2010-10-10 10:10:10.000000 +03:00');我希望值是用我定义的时区保存的,但实际值是:
2010-10-10 07:10:10.000000 +00:00
发布于 2022-11-22 14:06:41
带时区的时间戳这个名字也许很不幸,但几十年来一直是这样的,我们现在还在用它。
它最好被命名为absolute timestamp,它实际上存储的是UTC中的时间戳。它实际显示的是客户端定义的时区中的时间戳。
richard=> SELECT CURRENT_TIMESTAMP;
┌───────────────────────────────┐
│ current_timestamp │
├───────────────────────────────┤
│ 2022-11-22 14:03:57.919421+00 │
└───────────────────────────────┘
(1 row)
richard=> SET timezone = 'Europe/Paris';
SET
richard=> SELECT CURRENT_TIMESTAMP;
┌───────────────────────────────┐
│ current_timestamp │
├───────────────────────────────┤
│ 2022-11-22 15:04:10.943315+01 │
└───────────────────────────────┘
(1 row)如果您实际上想要维护时区偏移量,则需要单独存储偏移时间,或者需要区域名称(例如,“欧洲/巴黎”)。
请注意,它们在具有DST的区域中是不相同的。
https://stackoverflow.com/questions/74533443
复制相似问题