PostgreSQL timestamp踩坑记录
PostgreSQL timestamp踩坑记录 项目Timezone情况 NodeJS: UTC+08 PostgreSQL: UTC+00 timestampTest.js const { Client } = require('pg') const client = new Client() client.connect() let sql = `` client.query(sql, (err, res) => { console.log(err ? err.stack : res.rows[0].datetime) client.end() }) 不同时区 to_timestamp 查询结果 测试输入数据为 1514736000 (UTC时间 2017-12-31 16:00:00 ,北京时间 2018-01-01 00:00:00 ) 1、 timezone = UTC BEGIN; SET TIME ZONE 'UTC'; SELECT to_timestamp(1514736000) as datetime; END; 直接查询: 2017-12-31 16:00:00+00 YES pg查询: 2017-12-31T16:00:00.000Z YES 2、 timezone = PRC BEGIN; SET TIME ZONE 'PRC'; SELECT to