carbon 计算当前时间与给定时间差
$date = '2017-11-11 12:59:59';
$carbon = carbon::parse($date); // 格式化一个时间日期字符串为carbon对象
$int = (new Carbon)->diffInSeconds($carbon, false); // $int 为正负数
or $int = (new Carbon)->diffInSeconds($carbon, true); // $int 为正负数的绝对值
类似还有:
$int = (new Carbon)->diffInMinutes($carbon, true);
$int = (new Carbon)->diffInHours($carbon, true);
等等,可计算当前时间与给定的时间差。
某些时候,如果计算超过截至日期等等时候比较好用。
本作品采用《CC 协议》,转载必须注明作者和本文链接
本帖由系统于 3年前 自动加精