Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.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_Time_Strtotime - Fatal编程技术网

Php 减去两个字符串变量之间的差

Php 减去两个字符串变量之间的差,php,time,strtotime,Php,Time,Strtotime,我有两个包含时间的字符串,如下所示: 'ftime1' => string '17:44' (length=5) 'ftime2' => string '18:19' (length=5) 我需要计算frime2和ftime1之间的差异,因此结果为分钟 我试过了 $struct[$i]['ttime'] = time($struct[$i]['ftime2']) - time($struct[$i]['ftime1']); $struct[$i]['ttime2']

我有两个包含时间的字符串,如下所示:

  'ftime1' => string '17:44' (length=5)
  'ftime2' => string '18:19' (length=5)
我需要计算frime2和ftime1之间的差异,因此结果为分钟

我试过了

 $struct[$i]['ttime'] =  time($struct[$i]['ftime2']) - time($struct[$i]['ftime1']);
 $struct[$i]['ttime2'] =  strtotime($struct[$i]['ftime2']) - strtotime($struct[$i]['ftime1']);
 $struct[$i]['ttime3'] =  $struct[$i]['ftime2'] - $struct[$i]['ftime1'];
这导致:

  'ttime' => int 0
  'ttime2' => int 2100
  'ttime3' => int 1

strotime
将字符串转换为以秒为单位的时间戳。因此差异也将以秒为单位。执行
/60
分钟

(strtotime($struct[$i]['ftime2']) - strtotime($struct[$i]['ftime1'])) / 60;

时间函数的行为不是这样的,它返回当前的Unix时间戳,并且不接受任何参数。

time()
并没有做您认为它做的事情。它甚至不需要争论!真的,就像decez说的,RTFM。。。time()没有参数,只返回当前时间戳。