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

时间:2015-01-29 10:13:29

标签: sql postgresql datetime postgresql-9.3

有没有办法将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

输入数据无法添加TZtzis available in 9.4 not in 9.3无法添加{{3}}。

1 个答案:

答案 0 :(得分:4)

RFC3339只是ISO 8601的简介。

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

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

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