RAG*_*poR 1 iphone comparison nsdate
我正在开发闹钟.我想比较现在的时间和setTime.是否可以在几分钟内进行比较.
我的问题是NSDate会在几秒钟内进行比较,例如9:38:50不等于9:38:00.我怎么能在几分钟内比较?
首先,将它们转换为UNIX时间戳,忽略毫秒.
NSUInteger time1 = (NSUInteger)[date1 timeIntervalSince1970];
NSUInteger time2 = (NSUInteger)[date2 timeIntervalSince1970];
Run Code Online (Sandbox Code Playgroud)
忽略秒.
time1 = time1 - (time1 % 60);
time2 = time2 - (time2 % 60);
Run Code Online (Sandbox Code Playgroud)
现在,您可以安全地比较它们.
if (time1 == time2) {
NSLog(@"Bingo");
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
964 次 |
| 最近记录: |