【发布时间】:2021-05-04 16:48:39
【问题描述】:
我想在 Postgres 中获取一个 JSON 对象,该对象显示带有澳大利亚/悉尼时区偏移量的时间戳(夏令时期间为 +10:00 或 +11:00),例如,我希望返回具有以下值的 json 对象:
"2021-07-31T23:59:59.123456+10:00"
"2021-01-31T23:59:59.123456+11:00"
但是当我使用 to_json() 或 to_char() 时,返回的时间戳值是 UTC,偏移量为 +00:00
select to_json(current_timestamp::timestamptz),
to_char(current_timestamp::timestamptz, 'YYYY-MM-DD"T"HH24:MI:SS:MSOF')
“2021-01-31T07:47:22.895185+00:00”
2021-01-31T07:47:22:895+00
我尝试添加“在时区 'AEDT'”,但它会移动时间戳值并将偏移量保持为 +00:00。
谢谢。
【问题讨论】:
-
不相关,但是:
current_timestamp::timestamptz可以简化为current_timestamp
标签: postgresql timezone-offset timestamp-with-timezone to-char to-json