【问题标题】:PostgreSQL: insert sql statement with default timestamp - dbeaver vs phpPostgreSQL:使用默认时间戳插入 sql 语句 - dbeaver vs php
【发布时间】:2017-02-24 15:35:45
【问题描述】:

鉴于这个简单的表格:

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服务器时间没问题(即CET)。

我错过了什么?

【问题讨论】:

  • 在您的 PHP ini 文件中,检查选定的时区。编辑:其实不太清楚为什么这很重要
  • 听起来你错过了大约一个小时
  • @pteronewone 是一个很好的 :)
  • @Andy 我已经尝试设置 date_default_timezone_set('CET');

标签: php linux postgresql dbeaver sql-timestamp


【解决方案1】:

根据this link 的回答,将表定义更改为

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 2018-01-13
    • 1970-01-01
    • 1970-01-01
    • 2020-11-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多