Php 如何将日期添加到1年。在拉威尔
我对这句话有异议,有人能帮忙吗Php 如何将日期添加到1年。在拉威尔,php,laravel,Php,Laravel,我对这句话有异议,有人能帮忙吗 foreach ($vehicles as $vehicle) <tr> <td>{{ date('d F Y', strtotime($vehicle->created_at)) }}</td> <td>{{ date('d F Y', strtotime($vehicle->created_at), " +1 year") }}</td> foreach($veh
foreach ($vehicles as $vehicle)
<tr>
<td>{{ date('d F Y', strtotime($vehicle->created_at)) }}</td>
<td>{{ date('d F Y', strtotime($vehicle->created_at), " +1 year") }}</td>
foreach($vehicle作为$vehicle)
{{date('dfy',strottime($vehicle->created_at))}
{{date('dfy',strottime($vehicle->created_at),“+1年”)}
Laravel自动将在创建的包装到Carbon
实例,您可以使用addYear()
函数轻松添加年份。见文件,
更正的代码是
date('d F Y', strtotime($vehicle->created_at->addYear()))
要获得更多的良好实践,您可以使用@Rafael建议的代码来获得相同的结果
<td>{{ $vehicle->created_at->format('d F Y') }}</td>
<td>{{ $vehicle->created_at->addYear()->format('d F Y') }}</td>
{{$vehicle->created_at->format('dfy')}
{{$vehicle->created_at->addYear()->格式('dfy')}
+1年
应在
处使用$vehicle->created_创建,而不是作为第三个参数传递给date
函数。
代码:
date('d F Y', strtotime($vehicle->created_at . " +1 year") );
即使有。“+1年”不添加一年日期('dfy',strotime(strotime($vehicle->created_at),'+1年)
或日期('dfy',strotime($vehicle->created_at),'+1年)
哪种“问题”你有吗?那看起来不像是有效的PHP代码all@InforootIhalili你在尝试我的答案吗?非常感谢David,让它更简单:)$vehicle->created_at->addYear()->format('d F Y');@Rafael你说得对,我正在根据你的建议更新我的答案