gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 20:35:17 24 4
gpt4 key购买 nike

来自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'));

关于php - 使用PHP的Carbon时如何将日期设置为本月的第n天?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37206146/

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