PHP 如何获取两个时间之间的年和月份

2025-04-25 06:37:06
推荐回答(1个)
回答1:

$time1 = strtotime('2014-02-04'); // 自动为00:00:00 时分秒
$time2 = strtotime('2015-02-06');

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

print_r($monarr);