PHP - 从日期计算中提取周/日/小时/分钟

时间:2010-07-27 17:54:39

标签: php date

$dateDiff    = $mtime - $ctime;
$fullDays    = floor($dateDiff/(60*60*24));
$fullHours   = floor(($dateDiff-($fullDays*60*60*24))/(60*60));
$fullMinutes = floor(($dateDiff-($fullDays*60*60*24)-($fullHours*60*60))/60);
echo "Difference is $fullDays days, $fullHours hours and $fullMinutes minutes."; 

我希望增加看周的能力。我知道我可以重复相同的过程,但有一个库或更简单的方法吗?

1 个答案:

答案 0 :(得分:1)

在PHP 5.3及更高版本中,有DateTime类。请参阅http://php.net/manual/en/class.datetime.php