使用strtotime()计算时差(以小时和分钟为单位) [英] Calculating the time difference(in hours and minutes) using strtotime()

查看:67
本文介绍了使用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;

这篇关于使用strtotime()计算时差(以小时和分钟为单位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆