我寫這段代碼其中之一:如果我提供$ customDate像PHP:兩個同日聲明,但星期是錯誤的
if(!is_null($customDate)){
$referenceDate = strtotime($customDate);
$toDay = date("N", $referenceDate);
echo("/".$referenceDate."/".$toDay."/");
}
else{
$referenceDate = strtotime(date("d:m:y"));
$toDay = date("N");
echo("/".$referenceDate."/".$toDay."/");
}
:
函數名(「24: 7" 時17分);
它打印出這一點:
/2分之1500941237/
一個日期戳(我認爲)和2周的天 - 週二。
如果我不提供$ customDate和呼叫功能:
函數名();
我得到這個:
/1分之1500941237/
這又是 - 郵戳(我認爲)和1周的一天 - 週一。
第二個是正確的,它是24號,它是星期一。
我對PHP很新穎,所以我幾乎100%確定在操作日期時有一些細微差別,但我不確定它是什麼。
兩張相同的日期戳怎麼能產生不同的星期幾?
使用默認配置在Windows 10上的WAMP服務器上運行它。
全功能:
function nextDate($customDate=null){
$referenceDate;
$toDay;
if(!is_null($customDate)){
$referenceDate = strtotime($customDate);
$toDay = date("N", $referenceDate);
echo("/".$referenceDate."/".$toDay."/");
}
else{
$referenceDate = strtotime(date("d:m:y"));
$toDay = date("N");
echo("/".$referenceDate."/".$toDay."/");
}
}
nextDate( 「24:07:17」); - >給出了錯誤的結果,它說24日是星期二。
nextDate(); - >給出正確的結果,它說24日是星期一。
你能告訴我們處理日期後的代碼嗎? – GrumpyCrouton
@GrumpyCrouton沒有日期處理,我只是從函數外部調用nextDate()。 – iAmTheGuy96
我已經運行你的代碼在線編輯器,我還沒有看到任何問題都有相同的結果顯示在這兩種情況。 http://www.writephponline.com/ – rowmoin