首页 > 解决方案 > 未来的下一个奥古斯都与碳

问题描述

有没有更漂亮的方法来获得下一个 8 月 1 日的完整日期:

$year = date('Y') + 1;
if (date('j') >= 1 && date('j') <= 8) {
    $year = date('Y');
}
$nextAugust = '01-08-' . $year;
$nextAugust = Carbon::createFromFormat('d-m-Y', $nextAugust);

最好使用 Carbon PHP

标签: php-carbon

解决方案


以下代码使用碳对象找到下一个八月。

$nextAugust = Carbon::parse('first day of August' . (date('n') > 8 ? ' next year' : ''));

希望我的回答可以帮助您解决问题。


推荐阅读