php获得时间段的月

1.时间:
$start_time = $_GET[‘start_time‘]; //2015-01
$end_time = $_GET[‘end_time‘]; //2015-05
2.对时间进行拆分:
$time[‘start_time‘] = explode(‘-‘, $start_time);
$time[‘end_time‘] = explode(‘-‘, $end_time);

$j = $time[‘end_time‘][0] - $time[‘start_time‘][0]; //得到开始月
$year1 = $time[‘start_time‘][0];
$time1 = array();
$k = 1;
for ($i = $time[‘start_time‘][1]; $i <= $time[‘end_time‘][1] + $j * 12; $i++) {
if (!($i % 12)) $moth1 = 12;
else $moth1 = $i % 12;
$data = date(‘Y-m‘, strtotime($year1 . "-" . $moth1));
$non = $year1 . $moth1;
$time1[$k++] = $non;
if (!($i % 12)) $year1++;
}
得到结果 :2015-01 2015-02 2015-03 2015-04 2015-05

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。