Epoch time is based on 1970-01-01 00:00:00 UTC as standard time and will target time with 1970-01-01 00:00:00
The difference in time is calculated in seconds, in seconds, and can be negative values; Some applications store time in the Epoch time form to improve read efficiency,
The following shows the usage conversion method for the epoch time in pg.
--1 convert time stamp times to epoch time
Francs=> Select Extract (epoch from timestamp without time zone ' 1970-01-01 01:00:00 ');
Date_part
-----------
3600
(1 row)
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 Convert epoch time to 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)
The interpretation of the epoch in the--3 Handbook
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 '); 982384720.12 SELECT EXTRACT (EPOCH from INTERVAL ' 5 days 3 hours ');442800
Here's how can I 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 the use of new era time