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);
等等,可计算当前时间与给定的时间差。
某些时候,如果计算超过截至日期等等时候比较好用。

发表评论

电子邮件地址不会被公开。 必填项已用*标注