PostgreSQL时代时间转换 [英] PostgreSQL epoch time conversion

查看:147
本文介绍了PostgreSQL时代时间转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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.

从手册中引用:


它接受双精度精度参数,并从Unix纪元( seconds 从1970-01-01 00:00:00 + 00开始)转换为带有时区的时间戳

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

这篇关于PostgreSQL时代时间转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆