【问题标题】:php for this week and next本周和下周的php
【发布时间】:2017-03-01 17:34:40
【问题描述】:

我可以得到本周的星期一的日期,但是如何让它显示“和(下周星期一的日期)”?

例如,“2017 年 3 月 6 日至 13 日”

这是我目前所拥有的:

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

【问题讨论】:

  • 你能让 strtotime() 工作吗? "echo strtotime('下周一上午 9:00:00');"?
  • "" 显示“1488758400”
  • 是的,一个 unix 时间戳,您可以使用 date() 根据您的需要对其进行格式化。

标签: php date


【解决方案1】:

您可以使用更具可读性:

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

【讨论】:

  • 谢谢!我最终得到了这个:对于
  • @modernmagic 如果您觉得此答案对您有所帮助,请考虑将其标记为已接受。我看到你已经问了九个问题,但没有接受任何一个答案。接受答案让每个人都知道答案对您有帮助,同时也增加了您和回答者的声望。
【解决方案2】:

精确脚本:

$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 类,这也可能是你要学习的东西。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-29
    • 2013-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多