Home  >  Article  >  Backend Development  >  php计算时间差/两个时隔日期相隔的天数,时,分,秒

php计算时间差/两个时隔日期相隔的天数,时,分,秒

WBOY
WBOYOriginal
2016-06-13 10:39:04890browse

php计算时间差/两个时间日期相隔的天数,时,分,秒.


function?timediff(?$begin_time,?$end_time?)?
{?
????if?(?
$begin_time?$end_time?)?{?
????????
$starttime?=?$begin_time;?
????????
$endtime?=?$end_time;?
????}?else?{?
????????
$starttime?=?$end_time;?
????????
$endtime?=?$begin_time;?
????}?
????
$timediff?=?$endtime?-?$starttime;?
????
$days?=?intval(?$timediff?/?86400?);?
????
$remain?=?$timediff?%?86400;?
????
$hours?=?intval(?$remain?/?3600?);?
????
$remain?=?$remain?%?3600;?
????
$mins?=?intval(?$remain?/?60?);?
????
$secs?=?$remain?%?60;?
????
$res?=?array(?"day"?=>?$days,?"hour"?=>?$hours,?"min"?=>?$mins,?"sec"?=>?$secs?);?
????return?
$res;?
}?
//========?实例使用 ========?
$timediff?=?timediff(?strtotime(?"2011-10-28"?),?strtotime(?"2011-10-29"?)?);?
print_r(?$timediff?);?
?>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php运作的几种方式Next article:php fsockopen解决方法