PHP计算两个时间相差的天/时/分/秒


PHP #时间差2012-10-30 13:02

函数代码:

function shi_jian_cha($d,$d1)
{
	$time = strtotime($d) - strtotime($d1);
	$n_time = str_pad(floor($time/3600/24),2,0,STR_PAD_LEFT )."天".str_pad(floor($time%(24*3600)/3600),2,0,STR_PAD_LEFT )."小时".str_pad(floor($time%3600/60),2,0,STR_PAD_LEFT)."分".str_pad($time%3600%60, 2, 0, STR_PAD_LEFT)."秒";
	return $n_time;
}
调用示例:

$d = "2012-05-22 15:30:10";
$d1 = "2012-05-28 11:30:11";

echo shi_jian_cha($d1, $d);

// 05天20小时00分01秒


相关文章

粤ICP备11097351号-1