美文网首页
php 获取近一年的月份

php 获取近一年的月份

作者: 风度翩翩的程序猿 | 来源:发表于2021-06-28 16:49 被阅读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"));
        }

相关文章

网友评论

      本文标题:php 获取近一年的月份

      本文链接:https://www.haomeiwen.com/subject/vooqultx.html