2012-11-26 64 views
-1

可能重複:
How to echo 1st and 15th of the month in php插入新的一年日曆雙月調度

能夠打印出2012年12月1日&二○一二年十二月一十五日,但不能得到繼續過去那一點到2013年1月1日2013年1月15日依次等:

for($i=1;$i<=12;$i++){ 
date('M 1, Y', strtotime($i . "/1/" . date("Y"))); 
date('M 15, Y', strtotime($i . "/15/" . date("Y"))); 
} 
+1

如果你已經在你以前的問題上使用了我的解決方案,使用'DateTime'對象,而不是這個怪物,對你來說會更容易:) –

回答

0

date(「Y」) - 將輸出電流年,這就是爲什麼它是不會過去的1月1日,2012年

這樣的選項之一是

$currentYear = date('Y'); 
for ($year = $currentYear; $year < $currentYear + 3; $year++) 
{ 
    for($i=1;$i<=12;$i++){ 
     date('M 1, Y', strtotime($i . "/1/" . $year)); 
     date('M 15, Y', strtotime($i . "/15/" . $year)); 
    }  
} 

這將通過2012年,2013年,2014年