I would have thought these two statements would have returned the same value:
Javascript (Chrome)
new Date(2018, 3, 1).getTime() /1000;
=> 1522533600
Postgres
SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '2018-03-01 00:00:00 ');
=> 1519858800.0
As you can see there is a huge difference. What am I missing here?
Timezone information
Both queries are performed in the same timezone, confirmed as below.
Postgres
SELECT EXTRACT(TIMEZONE FROM now())/3600.0;
=> 2.0
Javascript
new Date().getTimezoneOffset();
-120
Solution
Thank you @yelliver and @Vao Tsun, the problem was that Javascript starts the month with zero. Confirming:
new Date(2018, 2, 1).getTime() /1000;
=> 1519858800