gpt4 book ai didi

PHP 时间函数显示错误值

转载 作者:行者123 更新时间:2023-11-29 22:35:56 24 4
gpt4 key购买 nike

我正在使用以下代码

list($date, $time) = explode(' ', $row['created_at']);
list($year, $month, $day) = explode('-', $date);
list($hour, $minute, $second) = explode(':', $time);
$timemodified = mktime($hour, $minute, $second, $month, $day, $year);

$threshold = time() - 6;

echo $threshold.'</br>';
echo $timemodified.'</br>';

echo $timemodified - $threshold;

输出

1428631618
1428643990
12372

修改时间为两分钟前。为什么差别这么大,我只是减去了六秒。我错过了什么吗?

最佳答案

这是因为 $threshold 时间并不是真正的 6 秒。您可以使用 strtotime() 函数将时间减去 6 秒

$newTime = strtotime('-6 seconds', $timemodified);
echo date('Y-m-d H:i:s', $newTime);

希望这有帮助。对于我的示例,请参阅:http://codepad.org/cRp858RG

关于PHP 时间函数显示错误值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29552222/

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