Laravel Carbon第二天的问题

问题描述 投票:0回答:1

我有此代码:

return Carbon::createFromFormat('Y-m-d', $given_date, $user_timezone)->next($user_day); //  $user_day = 'Monday';

给出错误:

未定义索引:星期一

感谢您的任何帮助。

php laravel-5.6 php-carbon
1个回答
0
投票

通过查看函数本身:

// Carbon\CarbonInterface
/**
     * Modify to the next occurrence of a given modifier such as a day of
     * the week. If no modifier is provided, modify to the next occurrence
     * of the current day of the week. Use the supplied constants
     * to indicate the desired dayOfWeek, ex. static::MONDAY.
     *
     * @param string|int|null $modifier
     *
     * @return static
     */
    public function next($modifier = null);

您可以得出您需要使用碳常数,即Carbon::MONDAY。查看类本身,解析为1

因此,您还可以将0(星期日)到6(星期六)的任何整数传递。

© www.soinside.com 2019 - 2024. All rights reserved.