//$startdate是開始時間,$enddate是結束時間 <?php $startdate="2011-3-15 11:50:00"; $enddate="2012-12-12 12:12:12"; $date=floor((strtotime($enddate)-strtotime($startdate))/86400); echo "相差天數:".$date."天<br/><br/>"; $hour=floor((strtotime($enddate)-strtotime($startdate))%86400/3600); echo "相差小時數:".$hour."小時<br/><br/>"; $minute=floor((strtotime($enddate)-strtotime($startdate))%86400/60); echo "相差分鍾數:".$minute."分鍾<br/><br/>"; $second=floor((strtotime($enddate)-strtotime($startdate))%86400%60); echo "相差秒數:".$second."秒"; ?>
PHP中計算兩個時間相差的天數、小時數、分鍾數、秒數