在 Postgres 中将 Unix 时间戳转换为 SQL 时间戳

Bra*_*don 6 postgresql timestamp datetime date

Date.now()我已经将和其他普通 Unix 时间戳值的结果传递1534360109480到 SQL 中,并通过以下方式运行它们:

"@converted_date" = to_timestamp("@date") AT TIME ZONE 'UTC';

而且它始终如一地返回50591-11-28 22:32:38

我不明白年份怎么可能是 50591,并且无论如何,日期/时间都不准确。

我究竟做错了什么?

mus*_*cio 6

to_timestamp接受秒精度的纪元值(“Unix 时间”),而您的值似乎具有毫秒精度。你需要做类似的事情

to_timestamp(@date/1000) AT TIME ZONE 'UTC';
Run Code Online (Sandbox Code Playgroud)