【发布时间】:2016-09-09 10:09:12
【问题描述】:
从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 对象?
【问题讨论】:
标签: php date datetime timestamp php-carbon