问题描述
我正在使用postgresSQL函数to_timestamp(双精度)将时间从时间戳转换为正常时间戳,但是我遇到的问题是时间戳不正确
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);
生成 47223-05-17 12:08:11.000064 + 02
produces "47223-05-17 12:08:11.000064+02"
应该是2015年4月3日,格林尼治标准时间+2:00 DST
while it should be 4/3/2015, 12:55:48 PM GMT+2:00 DST
SELCT to_timestamp(1428058557697);
产生 47223-05-17 14:41:36.999936 + 02
produces "47223-05-17 14:41:36.999936+02"
它应该是2015年4月3日,12:55:57
while it should be 4/3/2015, 12:55:57
可以看出日期已被完全转换为错误
as can be seen the dates have been converted totally incorrect
推荐答案
正如人们在给那些同样问题的人的评论中所解释的那样。函数to_timestamp()期望以秒为单位而不是毫秒,因此是解决方案。
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.
这篇关于PostgreSQL时代时间转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!