php datetime-> diff计算错误的小时数(太多3) [英] php datetime->diff is calculating wrong amount of hours (3 too much)

查看:102
本文介绍了php datetime-> diff计算错误的小时数(太多3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在php中有以下DateTime对象:

I've got the following DateTime object in php:

[start1] => DateTime Object ( 
    [date] => 2012-05-21 12:59:59
    [timezone_type] => 3
    [timezone] => Europe/Berlin
)

[end1] => DateTime Object ( 
    [date] => 2012-05-21 22:36:00
    [timezone_type] => 3
    [timezone] => Europe/Berlin
)

以及结果:

$time->end1->diff($time->start1

是:

DateInterval Object ( [y] => 0 [m] => 0 [d] => 0 [h] => 12 [i] => 36 [s] => 2 [invert] => 1 [days] => 0 )

为什么我得到的是12个小时而不是9个小时?

Why do I get an period of 12 hours and not 9?

推荐答案

我找到了解决方案...在进行差异处理之前,我对start1对象进行了sub()操作,现在我明白了为什么我的结果是错误的了。但我真的不知道为什么会这样。
http: //www.php.net/manual/en/datetime.sub.php#101175

I've found the solution...Before doing the diff I do a sub() on the start1 object. Now I've seen why my result is false... Here is the answer but I REALLY don't why this is happening. http://www.php.net/manual/en/datetime.sub.php#101175

这篇关于php datetime-> diff计算错误的小时数(太多3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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