gpt4 book ai didi

php - 存储在表中的时间大于现在

转载 作者:行者123 更新时间:2023-11-30 22:52:29 25 4
gpt4 key购买 nike

我有这种奇怪的情况。

我正在尝试将我存储在表中的时间转换为time-ago 格式。它在我的本地主机上运行良好,但在服务器上运行不佳。

出于某种原因,在计算现在和服务器时间之间的差异时,我收到一个负数。

这是一个例子:

$time = '2015-01-02 05:52:49'; //Time that is stored on the created cell
$now = time();
$seconds = strtotime($time);

$difference = $now - $seconds;

以上代码的输出是-13628

时区设置为 date_default_timezone_set('America/New_York');

我在这里错过了什么?

最佳答案

如果您运行它的日期/时间早于“2015-01-02 05:52:49”,那么 - 符号是合乎逻辑的。尝试改用它:

$date1 = new DateTime();
$date2 = new DateTime('2015-01-02 05:52:49');
$now = $date1->getTimestamp();
$seconds = $date2->getTimestamp();
$difference = $now - $seconds;

关于php - 存储在表中的时间大于现在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27738700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com