使用strtotime()计算时差(以小时和分钟为单位)
问题描述:
$time1 = strtotime('23:56');
$time2 = strtotime('00:21');
echo ($time1 - $time2)/60;
预期的o/p为 25
.但是它返回 1415
;
The expected o/p is 25
.But it returns 1415
;
如果我更改
$ time2 = strtotime('24:21');
它返回- 25
部分正确(因为它返回negative).
It returns -25
which is partially correct(since it returns negative ).
有人可以建议我,还有其他一些功能可以计算吗时差,以分钟为单位.
Can any one suggest me, some other function to calculate time difference in minutes.
谢谢:)
答
如果您仅在使用strtotime的情况下使用当前日期作为时间,则这样:
if you use strtotime with only a time it takes the current date so:
$time1 = strtotime('23:56'); // 2012-12-06 23:56
$time2 = strtotime('00:21'); // 2012-12-06 00:21
echo ($time1 - $time2)/60;