php判断两个时间差距,php判断两个时间的差

/***************

* @function 判断远程图片是否存在

* @Param:

* $url : 地址

* @Return: 返回结果

***************/

function isRealImg($url){

$ch = curl_init();

$timeout = 10;

curl_setopt ($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_HEADER, 1);

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

$contents = curl_exec($ch);

if (preg_match("/404/", $contents)){

return false;

}

return true;

}

/***************

* @function 计算两个时间的差

* @Param:

* $time_1 : 第一个参数

* $time_2 : 第二个参数

* $types : 类型:1--》相差天数,2--》相差小时数,3--》相差分钟数,4--》相差秒数,,默认1;

* @Return: $array 返回结果数组

***************/

function diffTime($time_1,$time_2,$types = 1){

if(!$time_1 || !$time_2){return false;}

if(strtotime(date('Y-m-d H:i:s',$time_1)) != $time_1) {

$time_1 = strtotime($time_1);

}

if(strtotime(date('Y-m-d H:i:s',$time_2)) != $time_2) {

$time_2 = strtotime($time_2);

}

if($time_1 < $time_2){

$temp = $time_1;

$time_1 = $time_2;

$time_2 = $temp;

}

switch ($types) {

case 1:

$diff = (strtotime(date('Y-m-d',$time_1)) - strtotime(date('Y-m-d',$time_2))) / (60*60*24);

break;

case 2:

$diff = (strtotime(date('Y-m-d H',$time_1).':00:00') - strtotime(date('Y-m-d H',$time_2).':00:00')) / (60*60);

break;

case 3:

$diff = (strtotime(date('Y-m-d H:i',$time_1).':00') - strtotime(date('Y-m-d H:i',$time_2).':00')) / 60;

break;

case 4:

$diff = $time_1 - $time_2;

break;

}

return $diff;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值