这是一个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