2013-03-13 91 views
0

我有以下代碼,除了$ the_saturday_after_next_sunday之外,一切正常。它沒有輸出正確的日期。你能幫我正確顯示日期嗎?下週日後獲取星期六的日期

感謝您的幫助。

<?php 
$today = date('m/d/Y'); 
$next_sunday = date('m/d/Y', strtotime("next Sunday")); 
$the_saturday_after_next_sunday = date('m/d/Y', strtotime("next Saturday", $next_sunday)); 

echo "today is: " . $today . "<br>"; 
echo "next sunday is: " . $next_sunday . "<br>"; 
echo "the saturday after next sunday is: " . $the_saturday_after_next_sunday . "<br>"; 
?> 

我也試過

$the_saturday_after_next_sunday = strtotime("next Saturday", $next_sunday); 
+1

[它只是在這裏](http://codepad.org/Kcv3Vpfj),你_did_記得正確設置你的時區? – Wrikken 2013-03-14 00:31:48

回答

2
$sunday = strtotime("next Sunday"); 
$saturday = $sunday + 60 * 60 * 24 * 6; 
echo date('m/d/Y', $saturday); 

這工作,因爲PHP 4.4,看到http://3v4l.org/SUnaR

+1

謝謝,這很好用! – cpcdev 2013-03-14 00:16:25

1

試試這個:

strtotime("next Saturday", strtotime($next_sunday)) 

相反的:

strtotime("next Saturday", $next_sunday) 
+0

你認爲'strtotime(strtotime(「下週日」))'(本質上是什麼)呢? – Wrikken 2013-03-14 00:34:13

相關問題