PHP獲取指定時間的前6個月月份、獲取前6天日期、獲取當月日期


//獲取前6個月月份
    public  function to_sex_month(){
        $today = input('param.today') ? input('param.today') : date("Y-m-d");
        $arr = array();
        $old_time = strtotime('-6 month',strtotime($today));
        for($i = 0;$i <= 6; ++$i){
            $t = strtotime("+$i month",$old_time);
            $arr[]=date('Y-m',$t);
        }
        return $arr;
    }

    //獲取前6天日期
    public  function to_sex_day(){
        $today = input('param.today') ? input('param.today') : date("Y-m-d");
        $arr = array();
        $old_time = strtotime('-6 day',strtotime($today));
        for($i = 0;$i <= 6; ++$i){
            $t = strtotime("+$i day",$old_time);
            $arr[]=date('Y-m-d',$t);
        }
        return $arr;
    }

 獲取當月日期

/**
 * 獲取當前月的所有日期
 * @return array
 */
 private function getMonthDays()
 {
     $monthDays = [];
     $firstDay = date('Y-m-01', time());
     $i = 0;
     $lastDay = date('Y-m-d', strtotime("$firstDay +1 month -1 day"));
     while (date('Y-m-d', strtotime("$firstDay +$i days")) <= $lastDay) {
         $monthDays[] = date('Y-m-d', strtotime("$firstDay +$i days"));
         $i++;
     }
     return $monthDays;
 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM