php处理时间

  //  时间
      function   wk($date1) {
        $datearr = explode("-",$date1);     //将传来的时间使用“-”分割成数组
        $year = $datearr[0];       //获取年份
        $month = sprintf('%02d',$datearr[1]);  //获取月份
        $day = sprintf('%02d',$datearr[2]);      //获取日期
        $his=substr($date1,strstr($date1," ")-5);
        $his_his = explode(" ",$date1);
        $datearr2 = explode(":",$his_his['1']);
        // print_r($datearr2);die;
        $h= $datearr2['0'];
        $i= $datearr2['1'];
        $s= $datearr2['2'];
        $d=daynum($day);
        $hour = $minute = $second = 0;   //默认时分秒均为0
        $dayofweek = mktime($hour,$minute,$second,$month,$day,$year);    //将时间转换成时间戳
        $shuchu = date("w",$dayofweek);      //获取星期值
        $weekarray=array("周日","周一","周二","周三","周四","周五","周六");
        $newdate=wkdata();
        if($newdate['y']==$year && $newdate['m']==$month)
        {
          if($newdate['d']==$d){
            return "今天 ".$h.":".$i;
            // return "今天 ".$h."时:".$i."分:".$s."秒";
          }else if($newdate['d']-$d==1){
            return "昨天 ".$h.":".$i;
            // return "昨天 ".$h."时:".$i."分:".$s."秒";
          }else if($newdate['d']-$d==2){
            return "前天 ".$h.":".$i;
            // return "前天 ".$h."时:".$i."分:".$s."秒";
          }else{
            return $month."月-".$day."日";
          }
        }
        else{
          return $year."-".$month."";
        }
        
     }
      function wkdata(){
      $date1=date("Y-m-d H:i:s");
      $datearr = explode("-",$date1);     //将传来的时间使用“-”分割成数组
      $year = $datearr[0];       //获取年份
      $month = sprintf('%02d',$datearr[1]);  //获取月份
      $day = sprintf('%02d',$datearr[2]);      //获取日期
      $day=daynum($day);
      return $arr=array("y"=>$year,"m"=>$month,"d"=>$day);
      }
      function daynum($day){
           $num=strlen($day);
           if($num == 2){
              $str=substr($day,0,1);
              if($str==0){
                $day=substr($day,1,2);
              }
           }
           return $day;
      }     
      //时间结束   
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_35835160/article/details/80333467
个人分类: php
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭