fourtwothree / daily-code

日常工作代码笔记
1 stars 0 forks source link

PHP获取两个时间点之间所有的月份? #13

Open fourtwothree opened 7 years ago

fourtwothree commented 7 years ago
    private function getMonthArr($time1, $time2)
    {
        $time1 = strtotime($time1); //
        $time2 = strtotime($time2);

        $monthArr = array();
        $monthArr[] = date('Y-m', $time1); // 当前月;
        while(($time1 = strtotime('+1 month', $time1)) <= $time2){
            $monthArr[] = date('Y-m',$time1); // 取得递增月;
        }

        return $monthArr;
    }