gpt4 book ai didi

php - 第一天!= "first day of this month"

转载 作者:可可西里 更新时间:2023-11-01 12:56:46 25 4
gpt4 key购买 nike

当使用“第一天”修改日期时,PHP 中有一个非常奇怪的行为。

'first day' ' of'? Sets the day of the first of the current month. (http://php.net/manual/de/datetime.formats.relative.php)

$currentMonthDate = new DateTime("2014-07-30 10:26:00.000000");
echo $currentMonthDate->format('Ym');

$currentMonthDate->modify('first day');
echo $currentMonthDate->format('Ym');

201407 / 201407 OK

$currentMonthDate = new DateTime("2014-07-31 10:26:00.000000");
echo $currentMonthDate->format('Ym');

$currentMonthDate->modify('first day');
echo $currentMonthDate->format('Ym');

201407 / 201408 WHY?

$currentMonthDate = new DateTime("2014-08-01 10:26:00.000000");
echo $currentMonthDate->format('Ym');

$currentMonthDate->modify('first day');
echo $currentMonthDate->format('Ym');

201408 / 201408 OK

我在运行 PHP 5.2 的生产服务器上发现了这种行为,所以我认为这是一个古老的错误,但它发生在我们测试服务器上的 PHP 5.3 ( http://phptester.net/ ) 和 5.5 中。

如果我在 PHP 5.2 中使用“本月的第一天”,则会发生相同的行为。在 PHP 5.5 中,“本月的第一天”按预期工作。

“第一天”的行为是错误吗?以及如何在 PHP 5.2 中获取“本月的第一天”而不在 stringdate 之间进行奇怪的转换?

最佳答案

这个问题似乎是文档问题。

From Derick in bug #51096: "first day" and "last day" should be "+1 day" and "-1 day".

The documentation should be updated to reflect this behaviour, as currently the "first/last day of" section says the "of" is optional when it is not.


更新

文档现已修复。所以 ' of '? 不再是可选的。

'first day of' Sets the day of the first of the current month.

关于php - 第一天!= "first day of this month",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25054592/

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