PostgreSQL epoch time conversion

三世轮回 提交于 2019-12-25 14:13:23

问题


I am using the postgresSQL function to_timestamp(double precision) to convert from epoch time to normal timestamp but I am facing a problem where the timestamp is incorrect

SELECT to_timestamp(1428058548491);

produces "47223-05-17 12:08:11.000064+02"

while it should be 4/3/2015, 12:55:48 PM GMT+2:00 DST

SELCT to_timestamp(1428058557697);

produces "47223-05-17 14:41:36.999936+02"

while it should be 4/3/2015, 12:55:57

as can be seen the dates have been converted totally incorrect


回答1:


As was explained from people In the comments for people who get the same problem. The function to_timestamp() expects it in seconds not milliseconds therefore that is the solution.

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



来源:https://stackoverflow.com/questions/29651196/postgresql-epoch-time-conversion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!