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 !


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM