开发者

PHP - Extracting weeks/days/hours/minutes from a date calc

开发者 https://www.devze.com 2023-01-09 06:46 出处:网络
$dateDiff= $mtime - $ctime; $fullDays= floor($dateDiff/(60*60*24)); $fullHours= floor(($dateDiff-($fullDays*60*60*24))/(60*60)开发者_JAVA技巧);
$dateDiff    = $mtime - $ctime;
$fullDays    = floor($dateDiff/(60*60*24));
$fullHours   = floor(($dateDiff-($fullDays*60*60*24))/(60*60)开发者_JAVA技巧);
$fullMinutes = floor(($dateDiff-($fullDays*60*60*24)-($fullHours*60*60))/60);
echo "Difference is $fullDays days, $fullHours hours and $fullMinutes minutes."; 

I am looking to add the ability to see weeks as well. I know I could just repeat the same process, but is there a library or an easier way?


In PHP 5.3 and up, there's the DateTime class. See http://php.net/manual/en/class.datetime.php.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号