zjlletian
V2EX  ›  PHP

咨询一个奇怪的 PHP 日期的 bug

  •  
  •   zjlletian · Mar 31, 2019 · 5211 views
    This topic created in 2774 days ago, the information mentioned may be changed or developed.
    <?php
    date_default_timezone_set("Asia/Shanghai");
    $today = date('Y-m-d');
    $week_start = date('Y-m-d', strtotime('this week'));
    $week_end = date('Y-m-d', strtotime('next week -1 day'));
    echo $today," ",$week_start," ",$week_end,"\n";

    同样的代码,在不同的环境下输出的结果不一样,有老哥帮忙解释一下么?。。。。

    自己电脑上 php5.6.40/7.1.23 输出 2019-03-31 2019-03-25 2019-03-31,是期望的正确结果
    服务器上 php5.6.9/5.5/5.4 都是输出 2019-03-31 2019-04-01 2019-04-07

    请问是哪里有问题,是 php 版本 bug ???
    10 replies  •  2019-04-01 09:32:41 +08:00
    zjlletian
    zjlletian
    OP
    Mar 31, 2019
    1
    找到了,果然是 php 的 bug。。https://bugs.php.net/bug.php?id=68603
    bzj
    bzj
    Mar 31, 2019
    2
    @zjlletian 下面说的不是已经修复了吗
    czb
    czb
    Mar 31, 2019 via Android
    3
    has been fixed as of PHP 5.6.23 and 7.0.8, respectively 而楼主跑的最新的都只到 5.6.9
    wdlth
    wdlth
    Mar 31, 2019
    4
    现在还有不用 DateTime, Carbon 的?
    agdhole
    agdhole
    Mar 31, 2019
    5
    用 Carbon
    st2udio
    st2udio
    Mar 31, 2019
    6
    Carbon 呀
    greed1is9good
    greed1is9good
    Mar 31, 2019
    7
    周起始日不一样吧,默认周日和默认周一。。。
    jugelizi
    jugelizi
    Mar 31, 2019❤️1
    8
    鸟哥,今天是 2018-07-31 执行代码:

    date("Y-m-d",strtotime("-1 month"))
    怎么输出是 2018-07-01?

    http://www.laruence.com/2018/07/31/3207.html
    tydl
    tydl
    Apr 1, 2019
    9
    zjlletian
    zjlletian
    OP
    Apr 1, 2019
    10
    @greed1is9good 跟这个没关系,这是 bug,在 5.6.23 就修复了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4562 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 100ms · UTC 09:42 · PVG 17:42 · LAX 01:42 · JFK 04:42
    ♥ Do have faith in what you're doing.