2010-06-02 93 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