PHP时间函数显示错误的值

时间:2015-04-10 02:13:44

标签: php mysql

我正在使用以下代码

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

修改时间仅为两分钟前。为什么差异如此之大,我只是减去六秒钟。我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

这是因为$threshold时间不是真正的6秒。您可以使用strtotime()功能从您的时间减去6秒

$newTime = strtotime('-6 seconds', $timemodified);
echo date('Y-m-d H:i:s', $newTime);
希望这会有所帮助。对于我的示例,请参阅:http://codepad.org/cRp858RG