搜索
首页php教程php手册php日期处理函数(计算时间差,转换时间戳日期)

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

Jun 13, 2016 am 09:54 AM
php函数处理教程日期时间时间差格式实际的计算转换


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;
 }
}

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解锁Myrise中的所有内容
3 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

功能强大的PHP集成开发环境

Atom编辑器mac版下载

Atom编辑器mac版下载

最流行的的开源编辑器

安全考试浏览器

安全考试浏览器

Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用