给定这个简单的表格:
create table comments (
id numeric not null,
comment text,
created timestamp not null default now()
);
直接在我的电脑上的数据库上使用 dbeaver,并执行此语句
insert into comments (id, comment)
select 1111, 'test';
新记录的“created”字段是:2017-02-24 16:17:21
这是我的正确时间 (CET)。
当我从 php 脚本(在连接到数据库的基于 linux 的网络服务器上运行)运行完全相同的语句时,结果是 2017-02-24 15:17:21
。
linux服务器时间ok(即CET)。
我错过了什么?
最佳答案
根据 this link 的回答,将表定义更改为
create table comments (
id numeric not null,
comment text,
created timestamp not null default (now() at time zone ('CET'))
);
这将使用所需时区的当前日期时间。
关于php - PostgreSQL:使用默认时间戳插入 sql 语句 - dbeaver 与 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42442539/