我有应该更改输出日期的这段代码,但是没有任何变化。谁能看到哪里出了问题?

<?php
$tempStartDate = "2011-07-04 15:00:00";
$TempDaysFromEvent = "-14";

$newtempStartDate = explode(" ", $tempStartDate);
echo "New Temp Start Date: ".$newtempStartDate[0];
echo "<br>";
list($year, $month, $day) = explode("-", $newtempStartDate[0]);
echo $year." ". $month. " ". $day;
echo "<br>";

$tempStartDate  =  $tempEndDate  =  date("Y-m-d", mktime(0,0,0,$month,($day+$tempDaysFromEvent),$year));
echo "TempStart Date:".$tempStartDate."<br>";

?>


这给了我这个输出:

New Temp Start Date: 2011-07-04
2011 07 04
TempStart Date:2011-07-04


但我希望它能给我:

New Temp Start Date: 2011-07-04
2011 07 04
TempStart Date:2011-06-20

最佳答案

定义$TempDaysFromEvent时您有一个大写字母,因此将其更改为

$tempStartDate  =  $tempEndDate  =  date("Y-m-d", mktime(0,0,0,$month,($day+$TempDaysFromEvent),$year));

08-25 15:50