【发布时间】:2019-06-08 07:48:29
【问题描述】:
我必须读取像 '20190608070000' 这样的字符串作为 UTC 中给出的时间戳。有没有简单的方法可以做到这一点?
这个采用 UTC 但需要格式化输入:
postgres=# show time zone;
TimeZone
----------
CET
(1 Zeile)
postgres=# select timestamp without time zone '2019-06-08 07:00:00' at time zone 'UTC';
timezone
------------------------
2019-06-08 09:00:00+02
(1 Zeile)
据我所知,to_timestamp() 总是将所有输入视为本地时间,因此输出以错误的方式移动:
postgres=# SELECT to_timestamp('20190608070000', 'YYYYMMDDHH24MISS') AT time zone 'UTC';
timezone
---------------------
2019-06-08 05:00:00
(1 Zeile)
其实我用的是 PostgreSQL 9.6。
【问题讨论】:
标签: postgresql timezone