问题描述
我将日期时间以bigint的形式存储在Postgres DB中,以毫秒为单位。我需要将它们转换为日期时间。函数to_timestamp()未考虑夏令时设置。 例如,我在数据库中具有以下值:
select username,created_timestamp,to_timestamp(created_timestamp/1000) from user_entity;
username | created_timestamp | to_timestamp
--------------------------+-------------------+-----------------------
user_15 | 1567066962775 | 2019-08-29 08:22:42+00
user_16 | 1581145146219 | 2020-02-08 06:59:06+00
我希望看到以下结果作为夏时制:
user_15 | 29.08.2019,09:22
user_16 | 08.02.2020,06:59
解决方法
如果将timezone
设置为要查看格式化的字符串的时区,则会得到所需的结果:
SET timezone = 'Europe/London';
PostgreSQL将timestamp with time zone
格式化为当前会话时区。