postgresql - 如何在 postgres 中将列数据从 GMT 时区转换为本地时间?
问题描述
我有一列“last_status_change_date”,其中包含 GMT 时间戳中的数据。我需要在“GMT-6”中转换这些数据。我怎样才能做到这一点?
select last_status_change_date from bss_calling_card where card_sn ='030400091074';
last_status_change_date
-------------------------
2020-01-03 17:06:51
(1 row)
结果集应该是这样的:
last_status_change_date
-------------------------
2020-01-03 11:06:51
(1 row)
解决方案
没有时区的时间戳谬误。尝试:
select (cast(last_status_change_date as timestamp with time zone) at time zone 'UTC') at time zone '-06:00' last_status_change_date from ...;
这将获取您的时间戳并将类型转换为带有时区的时间戳,然后通知 Postgres 它当前所在的时区,最后指示您想要的结果的时区。
推荐阅读
- javascript - 如何让函数 querySelectorAll 同时选择一个类和一个 src?
- azure - 请求者 IP 地址未列入白名单 - Azure Twilio Send Grid
- ruby-on-rails - 活动记录集合的自定义顺序
- flutter - 颤振-PhotoView
- blazor - 为什么在启用 AOT 编译的情况下没有为 blazor webbasesembly 生成 .wasm 文件?
- javascript - 开关按钮再次变为假
- angular - 部署在服务器上时,primeng 分页器无法正常工作 IE 11
- guzzle - 使用 Guzzle 服务实现分页
- javascript - 元素resetFields() 不生效
- amazon-web-services - 使用 AWS_CONTAINER_CREDENTIALS_RELATIVE_URI 找到的临时凭证到期:在第二个开头还是结尾?