简体   繁体   English

如何在这一天用碳获得周 +4

[英]how to get week +4 in this day with carbon

I have a problem here I want to get the +4 week date from the current date using carbon, the +4 week plan will be dynamic depending on the input entered by the user, how do I make it, I've tried using this code but it's time to step back我在这里有一个问题我想使用 carbon 从当前日期获取 +4 周日期,+4 周计划将根据用户输入的输入而动态变化,我该如何实现,我试过使用这个代码,但是时候退一步了

 $dt = Carbon::now();
        dd($dt->week(4)->format('Y-m-d'));

Check Carbon docs, you may use addWeeks() :检查 Carbon 文档,您可以使用addWeeks()

$dt = Carbon::now();
dd($dt->addWeeks(4)->format('Y-m-d'));

The week() method you've used, sets the week number using given first day of week and first day of year included in the first week.您使用的week()方法使用给定的第一天和第一周中包含的一年中的第一天设置周数。

I am not sure to understand your question, but I guess you just have to use :我不确定是否理解您的问题,但我想您只需要使用:

$dt = Carbon::now();
$dt->addWeeks(4);

dd($dt->format('Y-m-d');

You don't need carbon for such simple tasks.您不需要碳来完成如此简单的任务。 With DateTime使用日期时间

echo date_create('+4 weeks')->format("Y-m-d");

or with date and strtotime或使用日期和 strtotime

echo date("Y-m-d",strtotime('+4 weeks'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM