小编lar*_*arb的帖子

如何在 PHP 中计算两个时间(不是日期时间)之间的秒数差异。Laravel // PHP // Carbon

下面举一个例子来说明这个问题。下面的两个例子都给出了错误的区别:

// 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')); 
Run Code Online (Sandbox Code Playgroud)

我想要的是23:59:59与 相比00:00:01返回 2 秒的差异,并 00:00:0123:59:59.

php time laravel difference

1
推荐指数
1
解决办法
203
查看次数

标签 统计

difference ×1

laravel ×1

php ×1

time ×1