fourtwothree / daily-code

日常工作代码笔记

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

fourtwothree opened this issue · comments

    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;
    }