如何比较两个Zend_Date对象的日期部分? [英] How to compare the date parts of two Zend_Date objects?
本文介绍了如何比较两个Zend_Date对象的日期部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查是否在$ code> Zend_Date datetimes是在同一天。如何做到这一点?
I'd like to check if to Zend_Date
datetimes are on the same day. How can I do that?
$date1 = new Zend_Date('2011-11-14 10:45:00');
$date2 = new Zend_Date('2011-11-14 19:15:00');
推荐答案
$date1 = new Zend_Date('2011-11-14 10:45:00');
$date2 = new Zend_Date('2011-11-14 19:15:00');
if ($date1->compareDay($date2) === 0) {
echo 'same day';
}
另请参阅将日期与Zend日期进行比较
在旁注中,我强烈建议您验证是否需要 Zend_Date
。不要使用它,只因为它是ZF的一部分。大多数 Zend_Date
可以通过本机 DateTime
以及
On a sidenote, I strongly encourage you to verify if you have the need for Zend_Date
. Do not use it just because it is part of ZF. Most of what Zend_Date
does can be achieved faster and more comfortably with native DateTime
as well:
$date1 = new DateTime('2011-11-14 10:45:00');
$date2 = new DateTime('2011-11-14 19:15:00');
if ($date1->diff($date2)->days === 0) {
echo 'same day';
}
评论
如果你想比较是否是相同的日期只要做
EDIT after comments
If you want to compare whether it's the same date just do
$date1->compareDate($date2)
这篇关于如何比较两个Zend_Date对象的日期部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文