PostgreSQL 时间与Unix时间戳

网友投稿 824 2022-09-21

PostgreSQL 时间与Unix时间戳

PostgreSQL 时间与Unix时间戳

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=#

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:10个超有趣的Python项目,你会哪个?(python可以做哪些有趣的事情)
下一篇:day2-Samba
相关文章

 发表评论

暂时没有评论,来抢沙发吧~