如何将unix时间戳转换为带有时区的日期?

时间:2019-10-08 11:35:03

标签: sql postgresql date timestamp timezone

如何转换例如时间戳记:

1559347196759

使用PostgreSQL时区为'GMT + 2'的日期时间?

2 个答案:

答案 0 :(得分:3)

我相信这可以满足您的需求

select (timestamp 'epoch' + 1559347196759 * interval '1 millisecond') at time zone '+02:00'

第一个表达式将值转换为UTC。第二个会改变时区。

答案 1 :(得分:1)

将其转换为timestamp with time zone(绝对时间)并将其转换为适当的时区:

SELECT to_timestamp(1559347196759 / 1000.0) AT TIME ZONE '-02';

        timezone         
-------------------------
 2019-06-01 01:59:56.759
(1 row)