Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何计算同一天内两次之间的时差?_Php_Model View Controller_Codeigniter - Fatal编程技术网

Php 如何计算同一天内两次之间的时差?

Php 如何计算同一天内两次之间的时差?,php,model-view-controller,codeigniter,Php,Model View Controller,Codeigniter,我是CodeIgniter&PHP新手。 在我的数据库中,我将用户状态存储在“及时”和“超时”中。我想计算这个时间意味着,用户在某一天登录的时间。用户可能登录一次以上或在特定日期注销。 我怎样计算时间 时间格式为=04:06:37。 如果用户登录04:06:37,注销04:09:37,则时间差为3分零秒。使用将时间转换为时间戳,然后从原始时间减去最近的时间。比如, $to_time = strtotime("04:09:37"); $from_time = strtotime("04:06:37

我是CodeIgniter&PHP新手。 在我的数据库中,我将用户状态存储在“及时”和“超时”中。我想计算这个时间意味着,用户在某一天登录的时间。用户可能登录一次以上或在特定日期注销。 我怎样计算时间

时间格式为=04:06:37。
如果用户登录04:06:37,注销04:09:37,则时间差为3分零秒。

使用将时间转换为时间戳,然后从原始时间减去最近的时间。比如,

$to_time = strtotime("04:09:37");
$from_time = strtotime("04:06:37");
$time_diff = $to_time - $from_time;
echo gmdate('H:i:s', $time_diff);

使用将时间转换为时间戳,然后从原始时间减去最近的时间。比如,

$to_time = strtotime("04:09:37");
$from_time = strtotime("04:06:37");
$time_diff = $to_time - $from_time;
echo gmdate('H:i:s', $time_diff);
该函数执行您想要的操作

e、 g

该函数执行您想要的操作

e、 g


这是rgt,但在特定的日子里,用户可能在一个日期内输入或输出一次以上,我希望在一个日期内计算全天的时间。这是rgt,但在特定的日子里,用户可能在一个日期内输入或输出一次以上,我希望在一个日期内计算全天的时间。@JigarPandya我恢复了您的编辑,因为只对分钟进行总结是错误的。其余的呢?“OP可能会自己得到剩下的。@JigarPandya我恢复了您的编辑,因为只总结分钟是错误的。其余的呢?剩下的可能由行动小组自己负责。