gpt4 book ai didi

仅在生产服务器上使用 DateTime 的 PHP 真的很奇怪的不正确行为

转载 作者:搜寻专家 更新时间:2023-10-31 20:47:01 24 4
gpt4 key购买 nike

简单来说:

    $end   = new \DateTime();
$start = clone $end;

// Remove 30 days from today and set midnight
$start->sub(new \DateInterval('P30D'));
$start->setTime(0, 0);

var_dump(new \DateInterval('P30D'));
var_dump($start, $end); die();

输出(格式良好):

object(DateInterval)#1516 (8)
{ ["y"]=> int(0)
["m"]=> int(0)
["d"]=> int(30)
["h"]=> int(0)
["i"]=> int(0)
["s"]=> int(0)
["invert"]=> int(0)
["days"]=> int(0) }

object(DateTime)#1523 (3)
{ ["date"]=> string(19) "2012-06-19 00:00:00"
["timezone_type"]=> int(3)
["timezone"]=> string(11) "Europe/Rome"
}

object(DateTime)#4682 (3)
{ ["date"]=> string(19) "2012-08-18 02:42:23"
["timezone_type"]=> int(3)
["timezone"]=> string(11) "Europe/Rome"
}

1 个月的错误...有什么线索吗?

编辑:仅在使用时正确行为:

$start->modify('-30 days');

注释掉 DateInterval 行。

PHP 5.3.2-1ubuntu4.17 with Suhosin-Patch (cli) (built: Jun 19 2012 01:35:33)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with XCache v1.3.0, Copyright (c) 2005-2009, by mOo

Server version: Apache/2.2.14 (Ubuntu)
Server built: Feb 14 2012 18:09:18

最佳答案

许多 DateTime 错误已被 fixed since 5.3.2我在 5.3.16 上测试了你的代码,它工作正常,没有重复减法。

关于仅在生产服务器上使用 DateTime 的 PHP 真的很奇怪的不正确行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12014864/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com