1

鉴于这个简单的表:

create table comments (
  id numeric not null,
  comment text, 
  created timestamp not null default now()
);

从我的电脑直接在数据库上使用 dbeaver,并执行此语句

insert into comments (id, comment)
select 1111, 'test';

新记录的“创建”字段是:2017-02-24 16:17:21 这是我的正确时间(CET)。

当我从 php 脚本(在连接到数据库的基于 linux 的网络服务器上运行)运行相同的语句时,结果是2017-02-24 15:17:21. linux服务器时间没问题(也就是CET)。

我错过了什么?

4

1 回答 1

0

根据此链接的答案,将表定义更改为

create table comments (
   id numeric not null,
   comment text, 
   created timestamp not null default (now() at time zone ('CET'))
);

这将使用所需时区的当前日期时间。

于 2017-02-27T14:18:35.153 回答