Home >Backend Development >PHP Tutorial >PHP time calculation function for days and hours
<?php /* * 计算时间 * @param String $timestamp 需要被减的时间 * @param String $current_time 当前时间戳或者需要计算的时间戳 * @returne String 计算好的时间 */ function tmspan($timestamp,$current_time=0){ $timestamp = strtotime($timestamp); if(!$current_time) $current_time=time(); $span=$current_time-$timestamp; if($span<60){ return "刚刚"; }else if($span<3600){ return intval($span/60)."分钟前"; }else if($span<24*3600){ return intval($span/3600)."小时前"; }else if($span<(7*24*3600)){ return intval($span/(24*3600))."天前"; }else{ return date('Y-m-d',$timestamp); } }
The above introduces the PHP time calculation function of days and hours, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.