坑爹的php方法2 strtotime

http://d.hatena.ne.jp/bushimichi/20091101/1257007448/

 

 

写道
echo '前月 => '. date('m', strtotime('2009-10-31 -1 month')) .'<br>';
echo '今月 => '. date('m', strtotime('2009-10-31') ) .'<br>';
echo '翌月 => '. date('m', strtotime('2009-10-31 +1 month')) .'<br>';


------ 结果 ------
先月 => 10
今月 => 10
翌月 => 12

 

解决方法是每次都要用当月的1号来做+-月的计算

 

写道

echo '先月 => '. date('m', strtotime(date('Y-m-1').' -1 month')) .'<br>';
echo '今月 => '. date('m') .'<br>';
echo '翌月 => '. date('m', strtotime(date('Y-m-1').' +1 month')) .'<br>';

------ 结果 ------

前月 => 10
今月 => 11
翌月 => 12

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章