简体   繁体   中英

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

$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."; 

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM