您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP输出时间差函数代码_PHP教程

2024/3/15 20:33:29发布28次查看
php输出时间差函数
复制代码 代码如下:
在学习php 的时候,经常会用到获取现在之前或之后,某个时间段的日期。现在已经进行收集,大家同时也可以进行扩展丰富
复制代码 代码如下:
//获取当天的星期(1-7)
function getweek($times)
{
    $res = date('w', strtotime($times));
    if($res==0)
       $res=7;
    return $res;
}
//获取当天时间
function gettime($times)
{
    $res = date('h:i', strtotime($times));
    return $res;
}
//获取现在过几月的的时间
function getmonth($month,$type='l')
{
    if(!strcmp($type,'b'))
      $res=date(y-m-d h:i:s,strtotime(-$month months));
    if(!strcmp($type,'l'))
      $res=date(y-m-d h:i:s,strtotime(+$month months));
    return $res;
}
//获取当前时间
function getcurrentdatetime()
{
    $res=date(y-m-d h:i:s,time());
    return $res;
}
//获取当前时间隔几小时之前或之后的时间
function getdiffhours($hours,$type='l')
{
  if(!strcmp($type,'b'))
     $res=date(y-m-d h:i:s,strtotime(-$hours hour));
  if(!strcmp($type,'l'))
     $res=date(y-m-d h:i:s,strtotime(+$hours hour));
  return $res;    
}
//间隔几分钟之前或之后的时间
function getdiffminute($minute,$type='l')
{
  if(!strcmp($type,'b'))
     $res=date(y-m-d h:i:s,strtotime(-$minute minute));
  if(!strcmp($type,'l'))
     $res=date(y-m-d h:i:s,strtotime(+$minute minute));
  return $res;    
}
//间隔几秒之前或之后的时间
function getdiffsec($sec,$type='l')
{
  if(!strcmp($type,'b'))
     $res=date(y-m-d h:i:s,strtotime(-$sec second));
  if(!strcmp($type,'l'))
     $res=date(y-m-d h:i:s,strtotime(+$sec second));
  return $res;    
}//间隔几个星期之前或之后的时间
function getdiffweek($week,$type='l')
{
  if(!strcmp($type,'b'))
     $res=date(y-m-d h:i:s,strtotime(-$week week));
  if(!strcmp($type,'l'))
     $res=date(y-m-d h:i:s,strtotime(+$week week));
  return $res;    
}
// 间隔几天之间的时间
function getdiffdays($days,$type='l')
{
  if(!strcmp($type,'b'))
     $res=date(y-m-d h:i:s,strtotime(-$days day));
  if(!strcmp($type,'l'))
     $res=date(y-m-d h:i:s,strtotime(+$days day));
  return $res;    
}
//间隔几年之前或之后的时间
function getdiffyears($year,$type='l')
{
  if(!strcmp($type,'b'))
     $res=date(y-m-d h:i:s,strtotime(-$year year));
  if(!strcmp($type,'l'))
     $res=date(y-m-d h:i:s,strtotime(+$year year));
  return $res;    
}
http://www.bkjia.com/phpjc/326523.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/326523.htmltecharticlephp输出时间差函数 复制代码 代码如下: ?php date_default_timezone_set('prc'); //默认时区 echo 今天:,date(y-m-d,time()),br; echo 今天:,date(y-m-d,strt...
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product