将 rfc3339 字符串转换为带时区的时间戳

Convert rfc3339 string to timestamp with timezone

有没有办法将 character varying 列中的 rfc3339 字符串正确转换为 timestamp with timezone

Input: "2015-01-28T17:41:52Z"
Expected output: "2015-01-28 17:41:52+00"
Current output: "2015-01-28 17:41:52+01"

我尝试了以下方法

/* begin dummy data */
WITH messages as (
    select 123 as id, '2015-01-28T17:41:52Z'::text as received
)
/* end dummy data */
SELECT id, received, (to_timestamp(received, 'YYYY-MM-DDThh24:MI:SS')) as d
FROM messages

无法为输入数据添加 TZtz,并且 OF is available in 9.4 but not in 9.3

RFC3339 只是 ISO 8601 的配置文件。

PostgregreSQL accepts any valid ISO 8601 inputdate/timestamp/timestamp with time zone。尝试投射,例如:

SELECT '2015-01-28T17:41:52Z'::timestamptz

注意:但是,您的输出(在您的客户端中)将始终在您的 current time zone.