我希望这段代码对你有帮助
function DifTime($T1,$T2){
$diff=abs($T2-$T1);
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
$hours = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24)/ (60*60));
$minuts = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60)/ 60);
$seconds = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60 - $minuts*60));
return array('Day'=>$days,'Month'=>$months,'Year'=>$years,'Hours'=>$hours,'Minuts'=>$minuts,'Seconds'=>$seconds);
}
样本:
$Data=DifTime(TIMESTAMP,(time()-TIMESTAMP)+TIMESTAMP);
printf("%d:%d:%d:%d", $Data['Day'], $Data['Hours'], $Data['Minuts'], $Data['Seconds']);
输出:
0:0:0:10