2010-06-02 46 views

回答

5

首先,將它們轉換爲UNIX時間戳忽略毫秒。

NSUInteger time1 = (NSUInteger)[date1 timeIntervalSince1970]; 
NSUInteger time2 = (NSUInteger)[date2 timeIntervalSince1970]; 

忽略秒。

time1 = time1 - (time1 % 60); 
time2 = time2 - (time2 % 60); 

現在,您可以安全地比較它們。

if (time1 == time2) { 
    NSLog(@"Bingo"); 
} 
+0

感謝您的建議iwat – RAGOpoR 2010-06-02 04:21:00

2

使用NSCalendar得到NSDateComponents你有興趣,然後可以很容易地比較這些。

雖然檢查當前日期是否晚於警報日期可能已足夠。如果是,並且警報沒有停止,即使計算機暫時失去電源或其他東西,也應該停止。

+0

感謝您的建議查克 – RAGOpoR 2010-06-02 04:20:19