Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP更新时,PostgreSQL时间戳字段的格式不相同_Php_Postgresql_Date_Timestamp - Fatal编程技术网

使用PHP更新时,PostgreSQL时间戳字段的格式不相同

使用PHP更新时,PostgreSQL时间戳字段的格式不相同,php,postgresql,date,timestamp,Php,Postgresql,Date,Timestamp,我在PostgreSQL中有一个带有时区字段的时间戳。 当我更新此字段时,我使用如下内容: $date = date('Y-m-d H:i:s'); 虽然SQL工作正常,但保存的日期似乎与带有时区日期的经典时间戳略有不同 更新时删除的数字可能是毫秒,但我不确定。 我想知道是否有一种方法可以用PHP获得相同格式的日期?你可以用它来获得微秒。你可以用它来获得微秒。如果你只需要一秒钟的时间戳分辨率,你必须相应地设计你的数据库,因为默认分辨率比一秒钟好 例如,使用以下列定义: last_access_

我在PostgreSQL中有一个带有时区字段的时间戳。 当我更新此字段时,我使用如下内容:

$date = date('Y-m-d H:i:s');
虽然SQL工作正常,但保存的日期似乎与带有时区日期的经典时间戳略有不同

更新时删除的数字可能是毫秒,但我不确定。
我想知道是否有一种方法可以用PHP获得相同格式的日期?

你可以用它来获得微秒。

你可以用它来获得微秒。

如果你只需要一秒钟的时间戳分辨率,你必须相应地设计你的数据库,因为默认分辨率比一秒钟好

例如,使用以下列定义:

last_access_time timestamp with time zone not null
    default date_trunc('second',now())
    constraint last_access_time_full_second check (
        date_trunc('second',last_access_time)=last_access_time
    )

如果您只需要一秒钟的时间戳分辨率,那么您必须相应地设计数据库,因为默认情况下分辨率比一秒钟好

例如,使用以下列定义:

last_access_time timestamp with time zone not null
    default date_trunc('second',now())
    constraint last_access_time_full_second check (
        date_trunc('second',last_access_time)=last_access_time
    )

不幸的是,列定义可能要简单得多(至少是默认值的部分):last_access_time time Stamp(0)和时区默认当前时间戳不幸的是,列定义可能要简单得多(至少是默认值的部分):last_access_time Stamp(0)和时区默认当前时间戳