日期:2014-05-17  浏览次数:20394 次

时间计算有问题啊...列出最近的前后6个月
<?

$arr = array();
$nowd = date("Ym");
$arr[] = date("Ym",strtotime("-6 month"));
$arr[] = date("Ym",strtotime("-5 month"));
$arr[] = date("Ym",strtotime("-4 month"));
$arr[] = date("Ym",strtotime("-3 month"));
$arr[] = date("Ym",strtotime("-2 month"));
$arr[] = date("Ym",strtotime("-1 month"));

$arr[] = date("Ym");

$arr[] = date("Ym",strtotime("+1 month"));
$arr[] = date("Ym",strtotime("+2 month"));
$arr[] = date("Ym",strtotime("+3 month"));
$arr[] = date("Ym",strtotime("+4 month"));
  $arr[] = date("Ym",strtotime("+5 month"));
$arr[] = date("Ym",strtotime("+6 month"));

for($i=0;$i<count($arr);$i++){
echo "<a href='?month=".$arr[$i]."'>".$arr[$i]."</a>,";
if($i%3==0)
echo '<br>';
}


?>

打印出来中间有2个 201203

201204不见了...

只有今天 2012 03 31 全天 的时候出现 平时都是正常的,求分析...

测试的时候请各位把日期设置为3.31号看看.

------解决方案--------------------
还是用你的代码

$nowd = date("Y-m-1");
把形如
$arr[] = date("Ym",strtotime("-6 month"));
都改成形如
$arr[] = date("Ym",strtotime("-6 month $nowd"));
就可以了