我尝试比较 2 个日期时间并在分钟和秒内获得不同的值,并且在我引用此主题 How to get time difference in minutes in PHP 后是的,该代码可以显示不同的内容,但只需几分钟:
$to_time = strtotime("2008-12-13 18:42:00");
$from_time = strtotime("2008-12-13 18:41:58");
echo round(abs($to_time - $from_time) / 60,2). " minute";
那么如何从上面的代码中显示分和秒?我的 php 版本是 5.2.17
。
最佳答案
$minutes = round(abs($to_time - $from_time) / 60,2);
$seconds = abs($to_time - $from_time) % 60;
echo "$minutes minute, $seconds seconds";
关于php - 计算时间差(以分钟和秒为单位),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16431624/