我想检查我拥有的 NSDate
对象是过去还是现在(如果不是 future )。
我已经试过了,但它不起作用:
-(void)checkIfMuted
{
NSDate *muteOverDate=[[NSUserDefaults standardUserDefaults] objectForKey:@"muteOverDate"];
if ([muteOverDate timeIntervalSinceNow]<0.0) {
self.muteEnabled=YES;
return;
}
self.muteEnabled=NO;
NSLog(@"%@\n%@",[[NSDate date] description],[muteOverDate description]);
}
NSLog 打印: 2016-02-10 14:55:19 +0000
2016-02-10 15:54:32 +0000
知道为什么它不起作用吗?谢谢!
最佳答案
NSDate *now = [NSDate date];
if ([now compare:muteOverDate] == NSOrderedAscending) {
// muteOverDate is in the future
}
关于ios - 检查 NSDate 对象是否在过去,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35318664/