How to compare the date parts of two Zend_Date objects?(如何比较两个 Zend_Date 对象的日期部分?)
问题描述
我想检查 Zend_Date
日期时间是否在同一天.我该怎么做?
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 对象的日期部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何比较两个 Zend_Date 对象的日期部分?
![](/xwassets/images/pre.png)
![](/xwassets/images/next.png)
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01