444683462
V2EX  ›  问与答

php strtotime 问题

  •  
  •   444683462 · Dec 30, 2014 · 2133 views
    This topic created in 4182 days ago, the information mentioned may be changed or developed.

    $beginMon=strtotime("-1 week Monday");
    $endMon=strtotime("-1 week Tuesday")-1;
    echo date("Y-m-d H:i:s", $beginMon);
    echo('<br/>');
    echo date("Y-m-d H:i:s", $endMon);
    echo("<br />");

    //上面是获取本周一的开始与结束时间戳
    //结果如下:
    //2015-01-05 00:00:00(错误)
    //2014-12-29 23:59:59(正确)

    $beginSun=strtotime("+0 week Sunday");
    $endSun=strtotime("+1 week Monday")-1;
    echo date("Y-m-d H:i:s", $beginSun)."<br />";
    echo date("Y-m-d H:i:s",$endSun)."<br />";

    //上面获取的是本周末的开始与结束时间戳
    //结果如下:
    //2015-01-04 00:00:00
    //2015-01-11 23:59:59(错误)

    //以上案例都是在今天测试(非周末 因为周末)

    1 replies    2014-12-30 23:29:30 +08:00
    revlis7
        1
    revlis7  
       Dec 30, 2014
    dayname - Moves to the next day of this name.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1849 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 16:14 · PVG 00:14 · LAX 09:14 · JFK 12:14
    ♥ Do have faith in what you're doing.