ホームページ  >  記事  >  バックエンド開発  >  時間の計算に問題があります。前後 6 か月をリストしてください。

時間の計算に問題があります。前後 6 か月をリストしてください。

WBOY
WBOYオリジナル
2016-06-13 13:37:531280ブラウズ

時間計算有问题啊...最近の前後6ヶ月を列挙

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

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

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

for($i=0;$i echo "".$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"));
就可以了

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。