PostgreSQL 时间戳转毫秒值并去除小数位

PostgreSQL About 447 words

时间戳转毫秒值

使用extract函数及epoch from关键词。

select extract(epoch from (current_timestamp)) * 1000

输出

z-blog=# select extract(epoch from (current_timestamp)) * 1000;
     ?column?
-------------------
 1613011422272.017
(1 行记录)

去除小数位

使用trunc函数去除小数位(直接去除小数点后面几位,不做四舍五入处理)。

select trunc(extract(epoch from (current_timestamp)) * 1000);

输出

z-blog=# select trunc(extract(epoch from (current_timestamp)) * 1000);
     trunc
---------------
 1613011444878
(1 行记录)
Views: 6,419 · Posted: 2021-05-16

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh