<? $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个 201203201204不见了...只有今天 2012 03 31 全天 的时候出现  平时都是正常的,求分析...测试的时候请各位把日期设置为3.31号看看.

解决方案 »

  1.   

    不止是3.31
    如果是3.30,那么2月份也是没有的因为你是加减一个月,他实际是将月份加减一。由于目标月份没有那一天,所以月份就移到亚个月了
    你看这个for($i=-6; $i<7; $i++)
      echo date('Y-m-d', strtotime("+$i month 2012-3-31")), " $i", PHP_EOL;2011-10-01 -6
    2011-10-31 -5
    2011-12-01 -4
    2011-12-31 -3
    2012-01-31 -2
    2012-03-02 -1
    2012-03-31 0
    2012-05-01 1
    2012-05-31 2
    2012-07-01 3
    2012-07-31 4
    2012-08-31 5
    2012-10-01 6观察一下就清楚了
      

  2.   


    month 是按照30天计算的
      

  3.   

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