时间:2021-07-01 10:21:17 帮助过:5人阅读
francs=> select extract(epoch from timestamp without time zone ‘1970-01-01 02:00:00‘);
date_part
-----------
7200
(1 row)
francs=> select extract(epoch from interval ‘+1 hours‘);
date_part
-----------
3600
(1 row)
francs=> select extract(epoch from interval ‘-1 hours‘);
date_part
-----------
-3600
(1 row)
--2 将epoch 时间转换成 time stamp 时间
francs=> select timestamp without time zone ‘epoch‘ + 3600 * interval ‘1 second‘;
?column?
---------------------
1970-01-01 01:00:00
(1 row)
francs=> select timestamp without time zone ‘epoch‘ + 7200 * interval ‘1 second‘;
?column?
---------------------
1970-01-01 02:00:00
(1 row)
--3 手册上关于 epoch 的解释
For date and timestamp values, the number of seconds since 1970-01-01 00:00:00 UTC (can be negative);
for interval values, the total number of seconds in the interval
epoch
For date and timestamp values, the number of seconds since 1970-01-01 00:00:00 UTC (can be negative); for interval values, the total number of seconds in the interval
SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE ‘2001-02-16 20:38:40.12-08‘); Result: 982384720.12 SELECT EXTRACT(EPOCH FROM INTERVAL ‘5 days 3 hours‘); Result: 442800
Here is how you can convert an epoch value back to a time stamp:
SELECT TIMESTAMP WITH TIME ZONE ‘epoch‘ + 982384720.12 * INTERVAL ‘1 second‘;
http://www.postgresql.org/docs/9.1/static/functions-datetime.html
PostgreSQL: epoch 新纪元时间的使用
标签: