Laravel 获取下一个日历日期

Laravel get next calendar date

例如,我从用户那里得到数字 25,我如何使用 Carbon 或任何 PHP 助手生成完整的日期?

For example today is 22 April 2015, then it will returns 25 April 2015.

If today is 26 April 2015, then it will returns 25 May 2015.

$date = 25;

$now = new DateTime();
$then = clone $now;
$then->setDate($now->format('Y'), $now->format('m'), $date);
if ($then < $now) {
    $then->add(new DateInterval('P1M'));
}
echo $then->format('Y-m-d');

这与@MarkBaker 的方法基本相同,但它使用 Carbon:

$next = 25;

$date = Carbon::today()->day($next);
if($date->isPast()){
    $date->month++;
}

echo $date;