PHP carbon 计算当前时间与指定时间差

项目中有计算当前时间与指定时间差的需求,记录下实现代码。

$date = '2020-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);

Enjoy it !

原文地址:https://www.cnblogs.com/daizhongxing/p/13851317.html