我知道之前已经多次询问过,但我似乎找不到合适的答案。我想计算两个unix时间戳之间的差异,并以天为单位显示这种差异。我不关心这里的几分钟或几秒钟。
$time = 172800 - time() + 1265010604;
echo floor($time/86400);
其中1265010604是今天的时间戳,172800是3天的偏移量。感谢
答案 0 :(得分:0)
$now = time();
$then = time() - 172800;
$difference = $now - $then;
echo "It was ".floor($difference / 86400)." days ago";
答案 1 :(得分:0)
我想计算两个unix时间戳之间的差异 并以天显示这种差异
这句话记录了你的要求,并提出了一个直截了当的方法:
$difference = abs($t0 - $t1);
$days = floor($difference / 86400);
答案 2 :(得分:0)
/* First second of the day */
function dayStart ($date) {
return mktime(0, 0, 0, date('n', $date), date('j', $date), date('Y', $date));
}
/* Get count of days between dates */
function daysBetween ($dateStart, $dateEnd) {
return round((dayStart($dateEnd) - dayStart($dateStart)) / (24 * 60 * 60));
}