与此时间戳一起使用的函数是什么?

Ada*_*ath 4 postgresql timestamp java

我有时间戳(存储为 BIGINT)格式,我无法变成人类可读的格式:

1462975819250
Run Code Online (Sandbox Code Playgroud)

它指向 2016 年 5 月 11 日的日期。但是函数 to_timestamp() 将其转换为:

48329-11-10 13:00:49.999872+01
Run Code Online (Sandbox Code Playgroud)

我想创建一个可以显示这些值的 VIEW,不知道要使用什么函数。

该字段由 Java 程序(我认为是 EclipseLink)编写。我没有程序的源代码。

小智 8

to_timestamp()期望参数以秒为单位给出。您的价值以毫秒为单位。只需将其除以 1000:

SELECT to_timestamp(1462975819.250);
Run Code Online (Sandbox Code Playgroud)

2016-05-11 16:10:19.25+02


ype*_*eᵀᴹ 6

似乎您正在存储毫秒,1970-01-01 00:00:00因此亚当的答案是正确的。另一种方法是对'epoch'时间戳使用间隔加法(即1970-01-01 00:00:00):

select timestamptz 'epoch' + 1462975819250 * interval '1 millisecond' 
       as my_timestamp ;
Run Code Online (Sandbox Code Playgroud)

测试:

test=# select timestamptz 'epoch' + 1462975819250 * interval '1 millisecond' 
              as my_timestamp ;
       my_timestamp        
---------------------------
 2016-05-11 15:10:19.25+01
(1 row)
Run Code Online (Sandbox Code Playgroud)

亚当斯:

test=# select to_timestamp(1462975819250 / 1000.0) ;
       to_timestamp        
---------------------------
 2016-05-11 15:10:19.25+01
(1 row)
Run Code Online (Sandbox Code Playgroud)

'epoch'时间戳:

test=# select timestamptz 'epoch' as the_start_of_times;
   the_start_of_times   
------------------------
 1970-01-01 01:00:00+01
(1 row)
Run Code Online (Sandbox Code Playgroud)

(1 小时差异+1是因为我的本地设置是 UTC+1。)

从相关的 Jaca 文档Class Timestamp

getTime

public long getTime()

返回自 1970 年 1 月 1 日格林威治标准时间 00:00:00 以来的毫秒数,由此 Timestamp 对象表示。

覆盖
getTime在课堂上Date

返回
自 1970 年 1 月 1 日格林威治标准时间 00:00:00 以来的毫秒数,由该日期表示。

也可以看看:
setTime(long)