gpt4 book ai didi

postgresql:如何将 UTC 时间戳转换为悉尼时间

转载 作者:行者123 更新时间:2023-11-29 11:56:34 26 4
gpt4 key购买 nike

我有一个 PostgreSQL 数据库,其中包含许多存储悉尼/澳大利亚本地时间时间戳的表。此外,我有一张表以 UTC 格式存储时间戳。这是无法更改的。

我的问题是——我需要使用什么 SQL 操作才能获得本地悉尼/澳大利亚时间的 UTC 时间戳?

我知道悉尼有夏令时,但我不确定如何编写 SQL 以便转换始终正确 - 无论时间戳是否在夏令时期间采用。

请指教。

谢谢,阿密特

最佳答案

使用 at time zone 如:

t=# select now() at time zone 'AEDT';
-[ RECORD 1 ]------------------------
timezone | 2016-10-11 08:20:39.067256

Time: 2.439 ms

有一个outdated list of timezones例如或者只使用 pg_timezone_names:

t=# select * from pg_timezone_names()  where name ilike '%sydney%';
-[ RECORD 1 ]----------------------
name | posix/Australia/Sydney
abbrev | AEDT
utc_offset | 11:00:00
is_dst | t
-[ RECORD 2 ]----------------------
name | Australia/Sydney
abbrev | AEDT
utc_offset | 11:00:00
is_dst | t

Time: 171.649 ms

关于postgresql:如何将 UTC 时间戳转换为悉尼时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39978767/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com