postgresql to_timestamp返回的时间与时间戳表示的日期不同

时间:2013-05-19 14:14:16

标签: javascript database postgresql

以下是问题的复制:

我现在通过JavaScript获取时间戳

var ts = +new Date // 1368971991090
console.log( new Date(1368971991090) ); // Sun May 19 2013 13:59:51 GMT+0000 (GMT)
然后在我的Postgres控制台中,

# select to_timestamp(1368971991090);
          to_timestamp          
--------------------------------
 45350-12-30 05:31:29.999872+00
(1 row)

未来的日期太多了。
The docs of JavaScript Date#getTime说它从纪元开始返回毫秒;与argument type Postgres' to_timestamp accepts相同。 Java的Date#getTime返回与JS Date#getTime相同的值。

1 个答案:

答案 0 :(得分:6)

从您的链接中的postgresql文档引用:

  

它接受双精度参数并从Unix纪元转换   (自1970-01-01 00:00:00 + 00以来的秒数)到时区的时间戳。

键 -

  

秒以来

在JS doc中:

  

自1970年1月1日00:00:00 UTC以来的毫秒数