Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 在Postgres中转换以毫秒为单位的时间戳_Sql_Postgresql_Timestamp - Fatal编程技术网

Sql 在Postgres中转换以毫秒为单位的时间戳

Sql 在Postgres中转换以毫秒为单位的时间戳,sql,postgresql,timestamp,Sql,Postgresql,Timestamp,我有一个以毫秒为单位的时间戳: 1420066991000 将其转换为UTC: Wed Dec 31 2014 23:03:11 及当地时间: Thu Jan 01 2015 00:03:11 但是,如果我试图在Postgres中使用to_timestamp将其转换为时间戳,它会给我一个错误的日期时间: select to_timestamp(1420066991000); 46970-02-17 13:03:20+00 由于要添加时间戳,我还做了以下操作: select to_time

我有一个以毫秒为单位的时间戳:

1420066991000
将其转换为UTC:

Wed Dec 31 2014 23:03:11
及当地时间:

Thu Jan 01 2015 00:03:11
但是,如果我试图在Postgres中使用to_timestamp将其转换为时间戳,它会给我一个错误的日期时间:

select to_timestamp(1420066991000);
46970-02-17 13:03:20+00
由于要添加时间戳,我还做了以下操作:

select to_timestamp(1420066991000.0);
46970-02-17 13:03:20+00
但结果是一样的

我的Postgres配置中是否缺少一些东西,比如时区设置?还是一个bug?

to_timestamp()
转换unix时间,即以秒为单位的时间。由于数据以毫秒为单位,因此应将其除以1000

select to_timestamp(1420066991000/1000);

如果需要,除以
1000.0
将允许您保持毫秒级精度。哦,我现在感觉到的脸掌。谢谢你的正确和有用的回答!