php时间戳获取时间

一:获取上个月1号----上月 月尾
function getlastMonthDays($date){
     $timestamp=strtotime($date);
     $firstday=date('Y-m-01',strtotime(date('Y',$timestamp).'-'.(date('m',$timestamp)-1).'-01'));
     $lastday=date('Y-m-d',strtotime("$firstday +1 month -1 day"));
     return array($firstday,$lastday);
 }
 
$times = getlastMonthDays(strtotime(date('Ymd'))); //返回数组
二:获取这个月所有天数封装数组
$days = date("t");
$arr=array();
for($i=1;$i<=$days;$i++){
$arr[]=date("Y-m")."-".$i;
}
三:获取指定时间所有数据
 
       $nus=array();
        $res=array();
        $datas=array();
        $t= date('t');
$date_start= strtotime(date('Ymd'));
        $month_start = strtotime(date('Ym01'));
        $days = date("t");
        $arr=array();
        for($i=1;$i<=$days;$i++){
        $arrs[]=date("Y-m")."-".$i;
         
        }
        $time="";
        foreach ($arrs as $va){
            $b=$va;
            $time.="'$b'".",";  //1号 -30号
        }
         
       $i= ( $date_start- $month_start )/86400; //今天是月内多少天数
        for($i;$i>=0;$i--){
            $cha="";
            $arr=array();
            $times=date('Y-m-d', strtotime("-$i days"));
            foreach ($data as $key=>$val){
                if(date("Y-m-d",$val['createtime'])==$times){
                    $cha.=$key.",";  //时间日期  2016-9-10
                }
                $nus[$times]=trim($cha,",");  //清除最后一位逗号
                $res[$times]=explode(",",$nus[$times]); //把符合当天的数据装在为一天数组里面
                if($res[$times][0]===""){  //如果为空转化为空数组(防止explode钻空)
                    $res[$times]=array();
                }
            }
            $arr['time']=$times;
            $arr["val"] =empty($res)?"0":count($res[$times]);
            $datas[] = $arr;
        }
        
        $peo="";
        foreach ($datas as $k=>$v){
             
            $a=$v['val'];
            $peo.="'$a'".",";
        }
       $time=trim($time,",");$peo=trim($peo,",");
        
    $chartArray = '{"labels":['.$time.'],"datasets":[{"fillColor":"rgba(151,187,205,0.2)","strokeColor":"rgba(151,187,205,1)","pointColor":"rgba(151,187,205,1)","pointStrokeColor":"#fff","pointHighlightFill":"#fff","pointHighlightStroke":"rgba(151,187,205,1)","label":"\u8fd1\u671f\u8bbf\u95ee\u91cf","data":['.$peo.']}]}';


nba2k2球员数据
请先登录后发表评论
  • 最新评论
  • 总共0条评论