• php 时间戳 总结 今日,昨日,上周,本周,最近三个月,上季,本季,去年,最近七天,今年,最近三十天


    if($time=="今日"){
                $beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
                $endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
                $begin = Date("Y-m-d",$beginToday);
                $end = Date("Y-m-d",$endToday);
            }else if($time=="昨日"){
                $beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
                $endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
                $begin = Date("Y-m-d",$beginYesterday);
                $end = Date("Y-m-d",$endYesterday);
            }else if($time=="上周"){
                $beginLastweek=mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'));
                $endLastweek=mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'));
                $begin = Date("Y-m-d",$beginLastweek);
                $end = Date("Y-m-d",$endLastweek);
            }else if($time=="本周"){
                //判断当天是星期几,0表星期天,1表星期一,6表星期六
                $w_day=date("w",time());
                //php处理当前星期时间点上,根据当天是否为星期一区别对待
                if($w_day=='1'){
                    $cflag = '+0';
                    $lflag = '-1';
                }else {
                    $cflag = '-1';
                    $lflag = '-2';
                }
                //本周一零点的时间戳
                $frist = strtotime(date('Y-m-d',strtotime("$cflag week Monday", time())));
                $begin = Date("Y-m-d",$frist); 
                $end = Date("Y-m-d",time()); 
            }else if($time=="本月"){
                $beginThismonth=mktime(0,0,0,date('m'),1,date('Y'));
                $endThismonth=mktime(23,59,59,date('m'),date('t'),date('Y'));
                $begin = Date("Y-m-d",$beginThismonth);
                $end = Date("Y-m-d",$endThismonth);
            }else if($time=="上月"){
                $beginLastmonth=mktime(0,0,0,date('m')-1,1,date('Y'));
                $endLastmonth=mktime(23,59,59,date('m')-1,date('t'),date('Y'));
                $begin = Date("Y-m-d",$beginLastmonth);
                $end = Date("Y-m-d",$endLastmonth);
            }else if($time=="最近三个月"){
                $beginThreemonth=mktime(23,59,59,date('m'),date('t'),date('Y'));
                $endThreemonth=mktime(23,59,59,date('m')-3,date('t'),date('Y'));
                $begin = Date("Y-m-d",$beginThreemonth);
                $end = Date("Y-m-d",$endThreemonth);
            }else if($time=="本季"){
                $begin = date('Y-m-d', mktime(0, 0, 0,$season*3-3+1,1,date('Y')));
                $end = date('Y-m-d', mktime(23,59,59,$season*3,date('t',mktime(0, 0 , 0,$season*3,1,date("Y"))),date('Y')));
            }else if($time=="上季"){
                $season = ceil((date('n'))/3);//当月是第几季度
                $begin = date('Y-m-d', mktime(0, 0, 0,$season*3-3-3+1,1,date('Y')));
                $end = date('Y-m-d', mktime(23,59,59,$season*3-3,date('t',mktime(0,0,0,$season*3,1,date("Y"))),date('Y')));
            }else if($time=="今年"){
                $begin = date('Y',time()). '-' ."01-01";
                $end = date('Y',time()). '-' ."12-31";
            }else if($time=="去年"){
                $d=strtotime('-1 years');
                $begin = date('Y',$d)."-01-01";
                $end = date('Y',$d)."-12-31";
            }else if($time=="最近七天"){
                $begin = date('Y-m-d', strtotime('-7 days'));
                $end = date('Y-m-d',time());
            }else if($time=="最近三十天"){
                $begin = date('Y-m-d', strtotime('-30 days'));
                $end = date('Y-m-d',time());
            }
  • 相关阅读:
    HDU 4472 Count DP题
    HDU 1878 欧拉回路 图论
    CSUST 1503 ZZ买衣服
    HDU 2085 核反应堆
    HDU 1029 Ignatius and the Princess IV
    UVa 11462 Age Sort
    UVa 11384
    UVa 11210
    LA 3401
    解决学一会儿累了的问题
  • 原文地址:https://www.cnblogs.com/invban/p/5163331.html
Copyright © 2020-2023  润新知