Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.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/7/image/5.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
计算错误时间-strotime,date()-PHP_Php_Datetime_Strtotime - Fatal编程技术网

计算错误时间-strotime,date()-PHP

计算错误时间-strotime,date()-PHP,php,datetime,strtotime,Php,Datetime,Strtotime,使用日期和strotime函数计算时间 $starttime = '11:55'; $endtime = '13:01'; //or '1:01' $totaltime = date("i",strtotime($endtime) - strtotime($starttime)); 我不知道为什么,但是echo$totaltimegiving06而不是66 它在其他时间范围内工作正常。i、 e代表12:30、13:30 感谢您的帮助。因为日期(“i”)仅显示从0到59的分钟数 一种可能的解决

使用日期和strotime函数计算时间

$starttime = '11:55';
$endtime = '13:01'; //or '1:01'
$totaltime = date("i",strtotime($endtime) - strtotime($starttime));
我不知道为什么,但是
echo$totaltime
giving
06
而不是
66

它在其他时间范围内工作正常。i、 e代表
12:30、13:30

感谢您的帮助。

因为日期(“i”)仅显示从0到59的分钟数

一种可能的解决办法:

$totaltime = (strtotime($endtime) - strtotime($starttime)) / 60;
因为日期(“i”)仅显示从0到59的分钟数

一种可能的解决办法:

$totaltime = (strtotime($endtime) - strtotime($starttime)) / 60;

返回值被格式化为新的时间输出(因为使用了date()函数)

由于您只请求格式化时间的分钟数,因此它只返回该部分

如果要查看小时和分钟,请使用h:

$totaltime = date("H:i",strtotime($endtime) - strtotime($starttime));
这将返回“01:06”

如果您需要两个日期之间的实际分钟数(因此您希望66作为结果),那么您不是在寻找格式化的时间字符串作为结果,而是一个包含分钟数的常规整数。您可以根据之前的计算进行计算,如下所示:

// divide total seconds between these points by 60, round down.
$totalMinutes = floor ( ( strtotime($endtime) - strtotime($starttime) ) / 60 );

返回值被格式化为新的时间输出(因为使用了date()函数)

由于您只请求格式化时间的分钟数,因此它只返回该部分

如果要查看小时和分钟,请使用h:

$totaltime = date("H:i",strtotime($endtime) - strtotime($starttime));
这将返回“01:06”

如果您需要两个日期之间的实际分钟数(因此您希望66作为结果),那么您不是在寻找格式化的时间字符串作为结果,而是一个包含分钟数的常规整数。您可以根据之前的计算进行计算,如下所示:

// divide total seconds between these points by 60, round down.
$totalMinutes = floor ( ( strtotime($endtime) - strtotime($starttime) ) / 60 );



我只需要几分钟,在这种情况下应该是66分钟。然后将小时数乘以60,再加上minutes@Erik当$endtime=“01:01”返回-654Yes时,因为在这种情况下,$endtime在$starttime之前,因此传递的分钟数将为负数。我只需要分钟,在这种情况下应该是66,然后将小时数乘以60,再加上minutes@Erik当$endtime=“01:01”返回时-654Yes,因为在这种情况下$endtime在$starttime之前,因此经过的分钟数将为负数。当$endtime=“01:01”返回时-654echo$totaltime=floor((strotime($endtime)-strotime)($starttime))/60);是使用相同的…返回负值当$endtime=“01:01”其返回-654echo$totaltime=floor((strotime($endtime)-strotime($starttime))/60);是使用相同的…返回负值