- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我的 PHP 脚本将运行几秒钟,我需要随时从 Postgres 数据库获取真实的时间戳。但是当我从 Postgres 获取 current_timestamp 时,它总是返回相同的值。
这是我的示例脚本(使用 DBAL):
echo "DB:" . $dbal->fetchColumn("select current_timestamp") . PHP_EOL;
echo "PHP: " . date("Y-m-d H:i:s") . PHP_EOL;
sleep(3);
echo "DB:" . $dbal->fetchColumn("select current_timestamp") . PHP_EOL;
echo "PHP: " . date("Y-m-d H:i:s") . PHP_EOL;
sleep(3);
echo "DB:" . $dbal->fetchColumn("select current_timestamp") . PHP_EOL;
echo "PHP: " . date("Y-m-d H:i:s") . PHP_EOL;
这是输出:
DB:2014-05-07 11:59:50.118+04
PHP: 2014-05-07 11:59:50
DB:2014-05-07 11:59:50.118+04
PHP: 2014-05-07 11:59:53
DB:2014-05-07 11:59:50.118+04
PHP: 2014-05-07 11:59:56
Postgres 安装在本地机器上。为什么它总是在同一时间返回?如何获得实时性?
我使用了 now() 函数,得到了相同的结果。Postgres 版本:9.3.4 x64。 PHP版本:5.5.11
最佳答案
来自 TFM , 突出显示我的:
9.9.4. Current Date/Time
PostgreSQL provides a number of functions that return values related to the current date and time. These SQL-standard functions all return values based on the start time of the current transaction:
CURRENT_DATE
CURRENT_TIME
CURRENT_TIMESTAMP
CURRENT_TIME(precision)
CURRENT_TIMESTAMP(precision)
LOCALTIME
LOCALTIMESTAMP
LOCALTIME(precision)
LOCALTIMESTAMP(precision)...
Since these functions return the start time of the current transaction, their values do not change during the transaction. This is considered a feature: the intent is to allow a single transaction to have a consistent notion of the "current" time, so that multiple modifications within the same transaction bear the same time stamp.
PostgreSQL also provides functions that return the start time of the current statement, as well as the actual current time at the instant the function is called. The complete list of non-SQL-standard time functions is:
transaction_timestamp()
statement_timestamp()
clock_timestamp()
timeofday()
now()
transaction_timestamp()
is equivalent toCURRENT_TIMESTAMP
, but is named to clearly reflect what it returns.statement_timestamp()
returns the start time of the current statement (more specifically, the time of receipt of the latest command message from the client).statement_timestamp()
andtransaction_timestamp()
return the same value during the first command of a transaction, but might differ during subsequent commands.clock_timestamp()
returns the actual current time, and therefore its value changes even within a single SQL command.timeofday()
is a historical PostgreSQL function. Likeclock_timestamp()
, it returns the actual current time, but as a formatted text string rather than a timestamp with time zone value.now()
is a traditional PostgreSQL equivalent totransaction_timestamp()
.
关于php - 当脚本工作时,Postgres now() 时间戳不会改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23512172/
给定一个带有多个 date_time 戳的字符串,我想 提取第一个戳及其前面的文本 候选字符串可以有一个或多个时间戳 后续的 date_time 戳记将被 sep="-" 隔开 后续date_time
是否可以合并从相机拍摄的文本和照片?我想在照片上标记日期和时间,但我在 Google 上找不到任何内容。 最佳答案 使用下面的代码来实现你所需要的。 Bitmap src = Bitm
有没有办法通过 Graph API 戳另一个用户?基于this post ,并使用 Graph Explorer ,我发布到“/USERID/pokes”,我已经授予它(Graph API 应用程序和
我有两个向左浮动的元素。一个是 body 的第一个 child ,另一个是容器的第一个 child ,容器是 body 的第二个 child 。 ...
我是一名优秀的程序员,十分优秀!