這是一個使問題清楚的示例。以下兩個示例都給出了錯誤的區別:// gives 86398 while the correct is 2sec$diff_in_sec = strtotime('23:59:59') - strtotime('00:00:01'); // again gives 86398 while the correct is 2sec.$diff_in_sec = Carbon::parse('00:00:01')->diffInSeconds(Carbon::parse('23:59:59')); 我想要的是23:59:59compared with00:00:01返回 2 秒的差異,和 00:00:01compare with 23:59:59。
2 回答

Smart貓小萌
TA貢獻1911條經驗 獲得超7個贊
您需要做的是將兩者都分配給變量,并查看第二次是否在第一次之前。如果是這樣,請添加一天。然后檢查差異:
$date1 = Carbon::parse('23:59:59');
$date2 = Carbon::parse('00:00:01');
if($date2->lt($date1)) {
$date2->addDay();
}
$date2->diffInSeconds($date1); // 2
- 2 回答
- 0 關注
- 89 瀏覽
添加回答
舉報
0/150
提交
取消