PHP Carbon "month()" 方法生成错误的日期时间

PHP Carbon "month()" method generates wrong DateTime

我刚刚偶然发现了一些非常奇怪的东西。我使用 "Carbon" 包来生成 DateTime 对象。

我使用以下代码为 2016 年 9 月开始创建 DateTime 字符串:

Carbon::create()->month(9)

如果我使用 Laravel 的 "dd()" 函数输出这个,我会收到以下输出:

Carbon\Carbon {
  +"date": "2016-10-01 10:22:36.000000"
  +"timezone_type": 3
  +"timezone": "Europe/Vienna"
}

它 returns 10 月 1 日,而不是 9 月 1 日!它每隔一个月工作正常。

我也试过这些:

Carbon::now()->month(9)
(new Carbon)->month(9)

但我得到了同样的错误结果。

有没有其他人遇到过这个错误,或者有人可以试试这个并告诉我你是否收到相同的输出?还是我只是做错了什么,尽管我什么都想不出来?

提前致谢。

我想问题出在今天是 31 号。

Carbon::create()->month(9) 尝试将 9 月设为同一天。由于 9 月没有 31 日,因此 returns 10 月 1 日。尝试:

Carbon::create()->day(1)->month(9);

Carbon::create()->startOfMonth()->month(9);

Carbon::create(null, 9);