function time_node($num){
//$num代表需要查询的月份,半年就是6,一年就是12
$mm = date('m',time())+1;
$yy = date('Y',time());
$m = 0;
while ($m < $num){
$mm = $mm-1;
if ($mm == 0){
$yy -= 1;
$mm = 12;
}
$time[] = $yy."-".$mm;
$m++;
}
return $time;
}
例:近半年的字符串格式日期
print_r(time_node(6));
结果: