php 时间戳一些示例

如根据当前时间 确定本天的起止时间

 // 获取当天的时间段内
  $nowdate = date("Y-m-d",time());
  $begintime = strtotime($nowdate);     //当天的开始 时间戳
  $endtime = $begintime + 60*60*24;  //当天的结束 时间戳
  $map['add_time'] = array(array('egt',$begintime),array('lt',$endtime),'AND');

如根据当前时间  确定本月的起止时间

     $nowmonth = date("m",time());         //获取当前月
    if($nowmonth == '01' || $nowmonth == '03' || $nowmonth == '05' || $nowmonth == '07' || $nowmonth == '08' || $nowmonth == '10' || $nowmonth == '12'){
            $nowdate = date("Y-m",time());
            $mstarttime = strtotime($nowdate); //本月的开始 时间戳
            $mendtime = $mstarttime + 31*60*60*24;

   }else if($nowmonth == '02'){
           $nowdate = date("Y-m",time());
           $mstarttime = strtotime($nowdate); //本月的开始 时间戳
           $mendtime = $mstarttime + 28*60*60*24;

  }else if($nowmonth == '04' || $nowmonth == '06' || $nowmonth == '09' || $nowmonth == '11'){

         $nowdate = date("Y-m",time());
         $mstarttime = strtotime($nowdate); //本月的开始 时间戳
         $mendtime = $mstarttime + 30*60*60*24; //本月的结束时间
}

$map['add_time'] = array(array('egt',$mstarttime),array('lt',$mendtime),'AND');

posted @ 2015-07-22 11:40  莫陌尘  阅读(253)  评论(0)    收藏  举报