2017-03-01 42 views
1

我可以拿到週一的日期爲當前周,但我怎麼得到它顯示「和(下週的週一日期)」?PHP爲本週和下週

例如, 「3月6日和13日,2017年」

這是我到目前爲止有:

<?php echo date('F j, Y',strtotime(date('o-\WW')));?> 
+0

你可以讓strtotime()工作嗎? 「echo strtotime('下週一,上午9:00:00');」? –

+0

「<?php echo strtotime('Next Monday');?>」displays「1488758400」 – modernmagic

+0

是的,一個unix時間戳,您可以根據需要使用date()來格式化它。 –

回答

4

您可以使用更具可讀性:

echo date('F j, Y',strtotime('Monday this week')); 
echo date('F j, Y',strtotime('Monday next week')); 
+1

謝謝!我結束了這個:對於<?php回聲日期('F j',strtotime('week Monday this'))??和<?php回聲日期('F j,Y',strtotime('星期一下週'));?> – modernmagic

+0

@modernmagic如果您覺得此答案對您有幫助,請考慮將其標記爲已接受。我看到你已經提出了九個問題,但沒有接受任何答案。接受答案讓每個人都知道答案對你有幫助,同時也增加了你和答覆者的代表。 – j08691

0

確切腳本:

$this_monday = date("F j", strtotime("Monday this week")); 
$next_monday = date("j, Y", strtotime("Monday next week")); 

echo $this_monday . " and " . $next_monday; 

問題將會過月。如果你需要做的是,你需要更多的邏輯,或許是這樣的:

$this_monday = strtotime("Monday this week"); 
$next_monday = strtotime("Monday next week"); 

if (date("F",$this_monday) === date("F",$next_monday)) { 

    echo date("F j", $this_monday) . " and " . date("j, Y", $next_monday); 

} else { 

    echo date("F j", $this_monday) . " and " . date("F j, Y", $next_monday); 
} 

有人可能到來並使用DateTime類,而不是建議,這可能是一個把你的名單上的學習,以及。

相關問題