第一天!="本月的第一天"

Fab*_*oni 7 php datetime

使用"第一天"修改日期时,PHP中有一种非常奇怪的行为.

'first day' ' of'?设置当前月份的第一天.(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');
Run Code Online (Sandbox Code Playgroud)

201407/201407 好的

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

$currentMonthDate->modify('first day');
echo $currentMonthDate->format('Ym');
Run Code Online (Sandbox Code Playgroud)

二十○万一千四百〇七/ 201408 为什么?

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

$currentMonthDate->modify('first day');
echo $currentMonthDate->format('Ym');
Run Code Online (Sandbox Code Playgroud)

201408/201408 好的

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

如果我在PHP 5.2中使用"本月的第一天",则会出现相同的行为.在PHP 5.5中,"本月的第一天"按预期工作.

是"第一天" - 行为是一个错误吗?如何在PHP 5.2中获得"本月的第一天"而不进行奇怪的转换stringdate

Fab*_*oni 4

看来这个问题是一个文档问题。

来自错误 #51096 中的 Derick:“第一天”和“最后一天”应该是“+1 天”和“-1 天”。

应更新文档以反映这种行为,因为目前“第一天/最后一天”部分表示“of”是可选的,但实际上不是。


更新

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

'first day of' 设置当月的第一天。