PostgreSQL to_timestamp返回的日期与时间戳所代表的日期不同 [英] postgresql to_timestamp returns different date than represented by the timestamp

查看:1157
本文介绍了PostgreSQL to_timestamp返回的日期与时间戳所代表的日期不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是问题的重复:

我现在通过JavaScript获得时间戳,为

I get the timestamp of now via JavaScript as


var ts = +new Date // 1368971991090
console.log( new Date(1368971991090) ); // Sun May 19 2013 13:59:51 GMT+0000 (GMT)


然后在我的Postgres控制台中,

Then in my Postgres console,

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

日期太多
JavaScript <$ c的文档$ c> Date#getTime 表示从纪元开始返回毫秒;与参数类型Postgres的 to_timestamp 接受。 Java的 Date#getTime 返回与JS Date#getTime 相同的值。

A date way too much into the future.
The docs of JavaScript Date#getTime say it returns milliseconds starting from the epoch; same as the argument type Postgres' to_timestamp accepts. Java's Date#getTime returns same value as JS Date#getTime.

推荐答案

从您的链接引用PostgreSQL文档:

Quote from postgresql doc from your link:


它接受双精度参数并从Unix时代
(自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.

键-


秒数自

seconds since

在JS文档中:


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

number of milliseconds since 1 January 1970 00:00:00 UTC

这篇关于PostgreSQL to_timestamp返回的日期与时间戳所代表的日期不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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