php日期处理函数(计算时间差,转换时间戳日期)_PHP教程

原创
2016-07-13 10:54:05 801浏览


php教程 转换时间戳为常用的日期格式与计算时间差:默认返回类型为“分钟”
function trans_time($timestamp){
if($timestamp else return date("y-m-d h:i:s",$timestamp);
}

//获取ip
function get_ip() {
if ($_server["http_x_forwarded_for"])
$ip = $_server["http_x_forwarded_for"];
else if ($_server["http_client_ip"])
$ip = $_server["http_client_ip"];
else if ($_server["remote_addr"])
$ip = $_server["remote_addr"];
else if (getenv("http_x_forwarded_for"))
$ip = getenv("http_x_forwarded_for");
else if (getenv("http_client_ip"))
$ip = getenv("http_client_ip");
else if (getenv("remote_addr"))
$ip = getenv("remote_addr");
else
$ip = "unknown";
return $ip;
}

//计算时间差:默认返回类型为“分钟”
//$old_time 只能是时间戳,$return_type 为 h 是小时,为 s 是秒
function timelag($old_time,$return_type='m'){
if($old_time echo '无效的unix时间戳';
}else{
switch($return_type){
case 'h':
$type = 3600; break;
case 'm':
$type = 60; break;
case 's':
$type = 1; break;
case '':
$type = 60; break;
}
$dif = round( (time()-$old_time)/$type ) ;
return $dif;
}
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/632349.htmlTechArticlephp教程 转换时间戳为常用的日期格式与计算时间差:默认返回类型为分钟 function trans_time($timestamp){ if($timestamp 1) echo '无效的unix时间戳'; e...
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。