37
A
回答
132
我所知道的最簡單的方法是:
if([firstDate timeIntervalSinceDate:secondDate] > 0) {
其他的答案涵蓋比較:,想添加一些香精;) 。
28
要比較日期使用-compare:
方法:
返回值如果:
- 接收機和anotherDate是 恰好彼此相等, NSOrderedSame
- 接收機是後面在 時間比另一個日期, NSOrderedDesc結束
- 接收器在時間上早於 , NSOrderedAscending。
11
17
怎樣......
if ([datStartDate earlierDate: datEndDate] == datStartDate) {
// datStartDate is earlier
} else {
// datEndDate is earlier
}
+0
非常感謝:) – Supertecnoboff 2016-06-29 10:04:41
2
斯威夫特2版接受的答案的:
if firstDate.timeIntervalSinceDate(secondDate) > 0 {
// firstDate is greater (further in the future) than secondDate
}
相關問題
- 1. 檢查一個unix_timestamp是否大於另一個
- 2. 如何檢查一個ID是否小於另一個
- 3. 如何檢查一個ActiveRecord類是否屬於另一個
- 4. AJV:檢查一個屬性是否等於另一個屬性
- 5. 檢查是否在一個ArrayList中值存在於另一個
- 6. 檢測是否含有的NSDate一個
- 7. 檢查值是否在另一個表
- 8. 是否有一個去檢查一個nvarchar是否比另一個小?
- 9. 檢查當前日期是否大於上一個星期一
- 10. 如何檢查一個數字是否比另一個數字大一些?
- 11. Vb.net檢查一個數是否是另一個數的多重
- 12. 檢查DIV是另一個
- 13. 檢查一個NSDate是否在本週使用當週
- 14. 如何檢查NSInteger是否比另一個NSinteger大?
- 15. 檢查一個ObservableCollection是否可以顯示另一個xaml!
- 16. jQuery - 你可以檢查一個類是否有另一個類?
- 17. 檢查一個文件是否包含另一個文件
- 18. 檢查一個文件是否從另一個進程打開
- 19. 檢查一個數組的值是否在另一個
- 20. 檢查一個nsstring是否與另一個字符串匹配
- 21. 檢查一個數是否爲另一個(其反向)的鏡
- 22. 檢查是否在另一個表中存在一個id
- 23. 爪哇 - 檢查是否一個圖像包含另一個
- 24. 檢查一個表的條目是否在另一個表中
- 25. 檢查一個數組是否是另一個數組的一個整數
- 26. 檢查當前類別是否屬於另一個類別
- 27. 在SQL和VB.NET中檢查日期是否小於另一個
- 28. SQL約束檢查值是否不存在於另一個表
- 29. 檢查變量是否小於另一個變量
- 30. PHP檢查cookie值是否等於另一個變量
聰明的想法:) +1 – lukya 2010-10-01 12:59:50
比用戶簡單得多NSDate比較:做得好! – 2013-06-09 09:40:47
是的,謝謝。 +1 – fnc12 2015-02-02 08:28:42