2010-03-15 82 views
0

我使用的是David Walsh PHP calendar腳本,需要格式化我的約會論點是這樣的:獲取日期字符串draw_calendar()函數

draw_calendar(7,2009);

我想得到今天的月份和年份以及下個月和之後的月份(所以當前月份加上一個加上一個月)。我如何連續三次調用函數來生成這三個日曆,只知道今天的月份和年份?

布蘭登

回答

1

我相信有更優雅的方式如何。然而就是:

$onemonth = strtotime('+1 month'); 
$twomonth = strtotime('+2 month'); 

draw_calendar(date('n'), date('Y')); 
draw_calendar(date('n', $onemonth), date('Y', $onemonth)); 
draw_calendar(date('n', $twomonth), date('Y', $twomonth)); 
+0

謝謝,我想這會工作。我不認爲我可以使用字符串,但strtotime()函數是有幫助的。 – Brandon 2010-03-17 22:40:02

0
function increment(&$month, &$year) { 
    if (++$month > 12) { 
     $month -= 12; 
     $year++; 
    } 
} 
$month = 11; 
$year = 2009; 
echo "Month: $month, Year: $year\n"; 
# Outputs Month: 11, Year: 2009 
increment($month, $year); 
echo "Month: $month, Year: $year\n"; 
# Outputs Month: 12, Year: 2009 
increment($month, $year); 
echo "Month: $month, Year: $year\n"; 
# Outputs Month: 1, Year: 2010