Blogger Information
Blog 19
fans 0
comment 2
visits 31223
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP计算两个时间差的方法
会飞的码蚁的博客
Original
1096 people have browsed it

PHP计算两个时间差的方法

// $createtime 开始时间戳,$endtime 结束时间戳
$startdate=date("y-m-d H:i:s",$createtime);
$enddate=date("y-m-d H:i:s",$endtime);

// floor — 舍去法取整
// float floor ( float $value )
// 返回不大于 value 的最接近的整数,舍去小数部分取整。

$date=floor((strtotime($enddate)-strtotime($startdate))/86400); // 天
$hour=floor((strtotime($enddate)-strtotime($startdate))%86400/3600%24); // 时
if ($hour < 10) {
	$hour = '0'.$hour;
}
$minute=floor((strtotime($enddate)-strtotime($startdate))%86400/60%60); // 分
if ($minute < 10) {
	$minute = '0'.$minute;
}
$second=floor((strtotime($enddate)-strtotime($startdate))%86400%60); // 秒
if ($second < 10) {
	$second = '0'.$second;
}
$timesize = $date. '天' .$hour. '小时' .$minute. '分钟' .$second. '秒';
echo '一共使用了'.$timesize; // 一共使用了2天08小时03分钟23秒


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post