php常用时间函数,php怎么计算脚本运行时间?

用户投稿 24 0

关于“php时间段查询”的问题,小编就整理了【2】个相关介绍“php时间段查询”的解答:

php怎么计算脚本运行时间?

startTime = microtime(true); //将获取的时间赋值给成员属性$startTime}//脚本结束处嗲用脚本结束的时间微秒值function stop(){$this->stopTime = microtime(true); //将获取的时间赋给成员属性$stopTime}//返回同一脚本中两次获取时间的差值function spent(){//计算后4舍5入保留4位返回return round(($this->stopTime-$this->startTime),4);}} $timer= new Timer();$timer->start(); //在脚本文件开始执行时调用这个方法usleep(1000); //脚本的主题内容,这里可以休眠一毫秒为例$timer->stop(); //在脚本文件结束处调用这个方法 echo "执行该脚本用时

".$timer->spent()."

"; ?>

PHP获取当前日期所在星期(月份)的开始日期与结束日期(实现代码)?

  代码如下:  // 获取指定日期所在星期的开始时间与结束时间  function getWeekRange($date){  $ret=array();  $timestamp=strtotime($date);  $w=strftime('%u',$timestamp);  $ret['sdate']=date('Y-m-d 00:00:00',$timestamp-($w-1)*86400);  $ret['edate']=date('Y-m-d 23:59:59',$timestamp+(7-$w)*86400);  return $ret;  }  // 获取指定日期所在月的开始日期与结束日期  function getMonthRange($date){  $ret=array();  $timestamp=strtotime($date);  $mdays=date('t',$timestamp);  $ret['sdate']=date('Y-m-1 00:00:00',$timestamp);  $ret['edate']=date('Y-m-'.$mdays.' 23:59:59',$timestamp);  return $ret;  }  // 以上两个函数的应用  function getFilter($n){  $ret=array();  switch($n){  case 1:// 昨天  $ret['sdate']=date('Y-m-d 00:00:00',strtotime('-1 day'));  $ret['edate']=date('Y-m-d 23:59:59',strtotime('-1 day'));  break;  case 2://本星期  $ret=getWeekRange(date('Y-m-d'));  break;  case 3://上一个星期  $strDate=date('Y-m-d',strtotime('-1 week'));  $ret=getWeekRange($strDate);  break;  case 4: //上上星期  $strDate=date('Y-m-d',strtotime('-2 week'));  $ret=getWeekRange($strDate);  break;  case 5: //本月  $ret=getMonthRange(date('Y-m-d'));  break;  case 6://上月  $strDate=date('Y-m-d',strtotime('-1 month'));  $ret=getMonthRange($strDate);  break;  }  return $ret;  }

到此,以上就是小编对于“php时间段查询”的问题就介绍到这了,希望介绍关于“php时间段查询”的【2】点解答对大家有用。

抱歉,评论功能暂时关闭!