使用 PHP 的 Carbon 时,如何将日期设置为本月的第 n 天?

How to set date to nth day of this month when using Carbon of PHP?

document page of Carbon library中可以看出,可以使用简单的词来初始化Carbon对象。例如,Carbon::parse('first day of December 2008')new Carbon('first day of December 2008')

但是,当我尝试通过以下试验将日期设置为本月 10 日时

Carbon::parse('10th day of this month')
Carbon::parse('tenth day of this month')
Carbon::parse('10th of this month')
Carbon::parse('tenth of this month')
Carbon::parse('10 of this month')
Carbon::parse('ten of this month')

所有这些都失败了。

目前我可以通过Carbon::parse('first day of this month')->addDays(9)创建我想要的Carbon对象,但是可读性不好。需要看更多的代码,第一次上釉时很容易误认为是本月9号。

那么,有没有一种方法可以只用一次解析来创建 Carbon 对象?

有点难看,但应该可以

Carbon::parse('10th ' . date('M'));