PHP 计算两段时间间隔


<?php 
$start  = strtotime ("2012-03-23 23:00:00");
$end    = strtotime ("2012-03-23 22:00:00");
$differ = $end - $start;
echo $differ;
//以秒为单位的间隔时间

$datetime1 = new DateTime("2012-04-16 04:58:52");
$datetime2 = new DateTime("2012-04-16 05:58:50");
$interval = $datetime1->diff($datetime2);
echo $interval->format('%R%a天%H小时%i分%s秒');
//用DateTime可以很方便格式化
?>

© 2012, 冰冻鱼. 请尊重作者劳动成果,复制转载保留本站链接! 应用开发笔记