Php 在Laravel blade中获取两个日期时间之间的时间差?

Php 在Laravel blade中获取两个日期时间之间的时间差?,php,laravel,datetime,Php,Laravel,Datetime,我有两个日期时间,第一个是用户的最后登录日期 {{ $message->recipient->last_login }} 在datetime格式中显示为“2017-05-11 02:56:18”,并且是当前时间 {{ date('Y-m-d H:i:s') }} 以相同的格式输出 基本上我想要的是得到两次之间的时差 差不多 @if (the time difference between the 2 dates is less than 10 minutes) do this @

我有两个日期时间,第一个是用户的最后登录日期

{{ $message->recipient->last_login }}
在datetime格式中显示为“2017-05-11 02:56:18”,并且是当前时间

{{ date('Y-m-d H:i:s') }}
以相同的格式输出

基本上我想要的是得到两次之间的时差

差不多

@if (the time difference between the 2 dates is less than 10 minutes)
do this
@endif

你必须选择碳日期。 在控制器中添加以下内容并将其传递给刀片服务器

$currentTime = Carbon::now();
在刀片模板中,按如下方式使用:

@if($currentTime->diffInMinutes($message->recipient->last_login) < 10)
    // your code
@endif
@if($currentTime->diffInMinutes($message->recipient->last_login)<10)
//你的代码
@恩迪夫

试试这个最简单的方法,这里我们使用
strotime
从时间中获得秒数

Laravel刀片语法:

{{intval((strtotime(date('Y-m-d H:i:s'))-strtotime("2017-05-11 02:56:18"))/60)}}


使用碳类这里的api供参考-
<?php

//getting time difference in seconds.
$secondsDifference=strtotime(date('Y-m-d H:i:s'))-strtotime('2017-05-11 02:56:18');
//converting seconds to minutes.
echo intval($secondsDifference/60);