views:

136

answers:

2

im developing Alarm Clock i want to compare a time now and setTime is it possible to compare in minute only.

My Problem is NSDate will compare in second example 9:38:50 are not equal 9:38:00 how can i compare in minute ? is it possible

thanks you for all advise.

+1  A: 

First, convert them to UNIX timestamp ignoring milliseconds.

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

Ignore seconds.

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

Now, you can safely compare them.

if (time1 == time2) {
  NSLog(@"Bingo");
}
iwat
thank you for your advise iwat
RAGOpoR
+2  A: 

Use NSCalendar to get the NSDateComponents you're interested in. Then it's easy to compare those.

Though it might be sufficient to check whether the current date is later than the alarm date. If it is and the alarm wasn't stopped, you should probably go off even if the computer momentarily lost power or something.

Chuck
thank you for your advise Chuck
RAGOpoR