php 获取近一年的月份

2021-06-28  本文已影响0人  风度翩翩的程序猿
$z = date('Y-m');
        $a = date('Y-m', strtotime('-12 months'));
        $begin = new DateTime($a);
        $end = new DateTime($z);
        $end = $end->modify('+2 month');
        $interval = new DateInterval('P1M');
        $daterange = new DatePeriod($begin, $interval, $end);
        $month = array();
        foreach ($daterange as $key => $date) {
            array_push($month, $date->format("Y-m"));
        }
上一篇下一篇

猜你喜欢

热点阅读