[英]Zend_Date::sub() and ISO_8601 calculating hour difference wrong
I want to calculate time difference between two Zend_Date objects (for countdown calculator): 我想计算两个Zend_Date对象之间的时差(用于倒数计算器):
$now = new Zend_Date($now_datetime, Zend_Date::ISO_8601);
$end= new Zend_Date($end_datetime, Zend_Date::ISO_8601);
echo $now->getIso();
echo $end->getIso();
$expires=array();
$expires['expired']=false;
if($end->isEarlier($now)){
$expires['expired']=true;
return $expires;
}
$dif=$end->sub($now);
$expires['days']=($dif->getDay()->toValue()/(60*60*24));
$expires['hours']=($dif->getHour()->toValue()/(60*60));
$expires['minutes'] = $dif->getMinute()->toValue()/60;
$expires['seconds'] = $dif->getSecond()->toValue();
var_dump($expires);
For $now_datetime =' 2012-06-30 01:01:01 ' and $end_datetime=' 2012-06-30 23:59:59 ', the result is 对于$ now_datetime =' 2012-06-30 01:01:01 '和$ end_datetime =' 2012-06-30 23:59:59 ',结果为
2012-06-30T01:01:01+02:00
2012-06-30T23:59:59+02:00
//array
'expired' => boolean false
'days' => int 0
'hours' => int 22
'minutes' => int 58
'seconds' => int 58
and it is OK. 没关系
But for For $now_datetime =' 2012-06-30 00:01:01 ' and $end_datetime=' 2012-06-30 23:59:59 ', the result is 但是对于$ now_datetime =' 2012-06-30 00:01:01 '和$ end_datetime =' 2012-06-30 23:59:59 ',结果为
2012-06-30T00:01:01+02:00
2012-06-30T23:59:59+02:00
//array
'expired' => boolean false
'days' => int 1
'hours' => int -1
'minutes' => int 58
'seconds' => int 58
and it is NOT OK. 而且还不行。 I expect 'hours' to be 23 , not -1 ?!
我希望“小时数”为23 ,而不是-1 ?!
I am running MAMP with php 5.3, Zend_Framework 1.10. 我正在使用php 5.3,Zend_Framework 1.10运行MAMP。 What is wrong with that?
怎么了 ISO_8601 is used for MySQL 'datetime' data and I don't wanto to change to mktime()...
ISO_8601用于MySQL的“日期时间”数据,我不想更改为mktime()...
try to set 尝试设置
date_default_timezone_set('UTC');
in your index.php.. it will work fine.. 在您的index.php ..它将正常工作..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.