PostgreSQL 纪元时间转换

PostgreSQL epoch time conversion

我正在使用 postgresSQL 函数 to_timestamp(双精度)将纪元时间转换为正常时间戳,但我遇到了时间戳不正确的问题

SELECT to_timestamp(1428058548491);

产生“47223-05-17 12:08:11.000064+02”

虽然应该是 2015 年 4 月 3 日,12:55:48 下午 GMT+2:00 DST

SELCT to_timestamp(1428058557697);

产生“47223-05-17 14:41:36.999936+02”

虽然应该是 4/3/2015,12:55:57

可以看出日期转换完全不正确

正如人们在遇到同样问题的人的评论中所解释的那样。函数 to_timestamp() 期望在几秒内而不是几毫秒内完成,因此这就是解决方案。

Quote from the manual:

it accepts a double precision argument and converts from Unix epoch (seconds since 1970-01-01 00:00:00+00) to timestamp with time zone