PHP头条
热点:

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



php教程 转换时间戳为常用的日期格式与计算时间差:默认返回类型为“分钟”
function trans_time($timestamp){
 if($timestamp < 1) echo '无效的unix时间戳';
 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 < 1){
  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.phpzy.comtrue/php/28123.htmlTechArticlephp日期处理函数(计算时间差,转换时间戳日期) php教程 转换时间戳为常用的日期格式与计算时间差:默认返回类型为分钟 function trans_time($timestamp){ if($timestamp 1) echo '无效的unix时间戳...

相关文章

    暂无相关文章

PHP之友评论

今天推荐