温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

PostgreSQL 时间与Unix时间戳

发布时间:2020-06-16 17:27:54 来源:网络 阅读:1453 作者:pgmia 栏目:系统运维

1.unix时间戳---》 时间



# SELECT TIMESTAMP WITH TIME ZONE 'epoch' + 1471313356 * INTERVAL '1 second';

        ?column?        

------------------------

 2016-08-16 10:09:16+08

(1 row)


# SELECT TIMESTAMP WITHOUT TIME ZONE 'epoch' + 1471313356 * INTERVAL '1 second';

      ?column?       

---------------------

 2016-08-16 02:09:16

(1 row)



# SELECT TIMESTAMP WITH TIME ZONE 'epoch' + 1461033436.269 * INTERVAL '1 second';

          ?column?          

----------------------------

 2016-04-19 10:37:16.269+08

(1 row)



毫秒



# SELECT TIMESTAMP WITH TIME ZONE 'epoch' + 1464186650352 * INTERVAL '1 milliseconds';

          ?column?          

----------------------------

 2016-05-25 22:30:50.352+08

(1 row)


# SELECT TIMESTAMP WITHOUT TIME ZONE 'epoch' + 1464186650352 * INTERVAL '1 milliseconds';

        ?column?         

-------------------------

 2016-05-25 14:30:50.352

(1 row)




2.时间----》 Unix时间戳



# SELECT EXTRACT(EPOCH FROM TIMESTAMP WITHOUT TIME ZONE '2016-05-25 14:30:50.352');

   date_part    

----------------

 1464186650.352

(1 row)


# SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '2016-05-25 14:30:50.352');

   date_part    

----------------

 1464157850.352

(1 row)



毫秒

# SELECT EXTRACT(EPOCH FROM TIMESTAMP WITHOUT TIME ZONE '2016-05-25 14:30:50.352')*1000;

   ?column?    

---------------

 1464186650352

(1 row)





postgres=# SELECT extract(epoch FROM '2017-02-07 11:18:23.098+08'::timestamp with time zone);

   date_part    

----------------

 1486437503.098

(1 row)


postgres=# select to_timestamp(1486437503.098);

        to_timestamp        

----------------------------

 2017-02-07 11:18:23.098+08

(1 row)


postgres=# 


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI