php 时间戳

来源:互联网 发布:秋天 连衣裙 搭配 知乎 编辑:程序博客网 时间:2024/05/18 01:06

今天这个时间戳困扰了我好久,之前是这样写的:

           if(strtotime('now') > strtotime(date('Y-m-d H:i:s',strtotime('+8 hours'))) 

            && strtotime('now') <strtotime(date('Y-m-d H:i:s',strtotime('+8 hours'))))

            //当在当天早上8点到晚上8点
        {
                    $date= "8:00";  
       }
     else if(strtotime('now') > (date('Y-m-d H:i:s',strtotime('+8 hours')))

           //当在当天之后晚上8点
         {
              $date= "20:00";
         }

 结果那天到下午4点后$date="20:00"了;后来调试才发现,strtotime(date('Y-m-d H:i:s',strtotime('+8 hours')))是以当前时间为基准的,后来改为

  if(strtotime('now') > strtotime(date('Y-m-d H:i:s',strtotime('today')+60*60*8)) 

     && strtotime('now') < strtotime(date('Y-m-d H:i:s',strtotime('today')+60*60*20)))
    {
              $_SESSION["zwork_time"]= "8:00";
    }
 else if(strtotime('now') > strtotime(date('Y-m-d H:i:s',strtotime('today')+60*60*20)) )
   {
             $_SESSION["zwork_time"]= "20:00";
    }

0 0
原创粉丝点击