English 中文(简体)
B. 利用NSD进行时间比较的必要性建议
原标题:Need advice about time comparison using NSDate

I am developing Alarm Clock. I want to compare a time now and setTime. Is it possible to compare in minutes only.

My Problem is NSDate will compare in seconds, for example 9:38:50 is not equal to 9:38:00. how can I compare in minutes?

最佳回答

首先,将其转换为UNIX,无视微秒。

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

Ignore seconds.

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

现在,你可以安全比较。

if (time1 == time2) {
  NSLog(@"Bingo");
}
问题回答




相关问题
Find the closest time from a list of times

So, here s the scenario. I have a file with a created time, and I want to choose a time from a list of times that that file s created time is closest or equal too...what would be the best way to ...

PHP Comparison Operators and Data Types

I m currently working through O Reilly s "Programming PHP" and have come across this table titled "Type of comparison performed by the comparison operators": First Operand | Second ...

Loop Until Condition Reached, iPhone

I have a problem here... After a button is pressed I want a loop to run until a condition is reached: - (IBAction)buttonclick1 ... if ((value2ForIf - valueForIf) >= 3) { ... I would like a loop ...

nuSoap or Zend Soap? [closed]

I would like to know the differences between nusoap and ZendSoap, which is the best? what benefits and disadvantages of each? Anyone who has used both technologies could make this comparison? Thank ...

Logic for a file compare

I trying to write a programm for file compare. For example: file1 1 2 3 4 5 file2 1 2 @ 3 4 5 If I do it line by line, I get: 1 == 1; 2 == 2; 3 != @; 4 != 3; 5 != 4; != 5; But, the truth is ...

热门标签