如何解决在created_at和当前时间在Laravel分钟之间的差异计算
我想在一个领域的时候有人在等待展示,我想通过在几分钟当前时间减去created_at时间去做这些事情。
这是我的表
<thead>
<tr>
<th scope="col">Ordernummer</th>
<th scope="col">E-mail</th>
<th scope="col">Kenteken</th>
<th scope="col">Wachttijd</th>
<th scope="col">Status</th>
</tr>
</thead>
<tbody>
@foreach($orders as $order)
<tr>
<th scope="row">{{ $order->ordernumber }}</th>
<td scope="row">{{ $order->email }}</td>
<th scope="row">{{ $order->numberplate }}</th>
<td scope="row">{{ $order->created_at }}</td>
<td scope="row">
@if( $order->status == 0)
Open
@else
Afgehandeld
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
和其中该写入<td scope="row">{{ $order->created_at }}</td>
我想表明那里分钟的差别。
由于已经
解决方法
我想你的$order->created_at
是碳的实例,所以你可以使用:
<td scope="row">{{ $order->created_at->diffInMinutes(\Carbon\Carbon::now()) }} minutes ago</td>
如果$order->created_at
是纯的MySQL格式不是碳实例只是转换/创建:
\Carbon\Carbon::createFromFormat('Y-m-d H:i:s',$order->created_at)->diffInMinutes(\Carbon\Carbon::now())
,
您可以像这样使用 Carbon
来计算以分钟为单位的差异
<td scope="row">{{ now()->diffInMinutes($order->created_at) }}</td>
,
您可以使用 Carbon::diffInMinutes
获得不同的分钟数,
或者您可以使用 Carbon::diffForHumans
获得更具可读性的语句
$order->created_at->diffInMinutes(Carbon::now());
// 那就是:5
$order->created_at->diffInMinutes(Carbon::now());
这将是:5 分钟前
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。