這是一個100%的工作代碼來完成任務
<?php
$month = date('n');
$year = date('Y');
$IsLeapYear = date('L');
$NextYear = $year + 1;
$IsNextYearLeap = date('L', mktime(0, 0, 0, 1, 1, $NextYear));
$TodaysDate = date('j');
if (strlen($month+3) < 10)
{
$UpdateMonth = "0".($month+3);
}
if ($month > 9) {
if ($month == 10)
{
$UpdateMonth = "01";
}
else if ($month == 11)
{
$UpdateMonth = "02";
}
else
{
$UpdateMonth = "03";
}
}
if (($month != 10) && ($month != 11) && ($month != 12))
{
if(($month&1) && ($TodaysDate != 31))
{
$DateAfterThreeMonths = $year."-".$UpdateMonth."-".$TodaysDate;
}
else if (($month&1) && ($TodaysDate == 31))
{
$DateAfterThreeMonths = $year."-".$UpdateMonth."-30";
}
else {
$DateAfterThreeMonths = $year."-".$UpdateMonth."-".$TodaysDate;
}
}
else if ($month == 11)
{
if (($TodaysDate == 28) || ($TodaysDate == 29) || ($TodaysDate == 30))
{
if ($IsLeapYear == 1)
{
$DateAfterThreeMonths = ($year+1)."-".$UpdateMonth."-28";
}
else if ($IsNextYearLeap == 1)
{
$DateAfterThreeMonths = ($year+1)."-".$UpdateMonth."-29";
}
else
{
$DateAfterThreeMonths = ($year+1)."-".$UpdateMonth."-28";
}
}
else
{
$DateAfterThreeMonths = ($year+1)."-".$UpdateMonth."-".$TodaysDate;
}
}
else
{
$DateAfterThreeMonths = ($year+1)."-".$UpdateMonth."-".$TodaysDate;
}
echo $DateAfterThreeMonths;
?>
我們可以在上面使用這段代碼手動檢查的東西: -
// Just change the values of $month, $year, $TodaysDate
$month = 11;
$year = 2012;
$IsLeapYear = date('L');
$NextYear = $year + 1;
$IsNextYearLeap = date('L', mktime(0, 0, 0, 1, 1, $NextYear));
$TodaysDate = 31;
只需複製和粘貼代碼,請在瀏覽器中查看:)
當'2012-01-31'是輸入時,你期望得到什麼? – 2012-04-23 06:40:23
我認爲你的問題沒有足夠明確的答案。例如,如果今天是1月31日呢?四月只有30天。 – 2012-04-23 06:41:23
我們無法回答你的問題,因爲我們不知道你想如何處理它。可能有一個功能可以做你想做的事,但我們不知道你想要什麼。你似乎在問如何爲無意義的問題找到正確的答案。你需要先決定你想要什麼問題的答案。 – 2012-04-23 06:49:21