本文介紹了如何比較兩個 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 對象的日期部分?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!