時間計算有有關問題啊列出最近的前後6個月
來源:互聯網
上載者:User
時間計算有問題啊...列出最近的前後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;$iecho "".$arr[$i].",";
if($i%3==0)
echo '
';
}
?>
列印出來中間有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"));
就可以了