我需要每天只检查一个代码块,我尝试了下面的代码,但它不符合我的要求。像今天的日期是25-5-2017,最后检查的日期是23-5-2017也不是在条件范围内。我不知道我在哪里做错了。
NSDate *todayDate = [NSDate date];
NSLog(@"today date is %@",todayDate);
NSDate *lastCheckedDate = [[NSUserDefaults standardUserDefaults] objectForKey:@"LastCheckedDate"];
NSLog(@"lastCheckedDate is %@",lastCheckedDate);
if ([todayDate compare:lastCheckedDate] > 864000.0f) {
NSArray *appMsgsArray = [response valueForKey:@"AppMsgs"];
NSDictionary *mainDict = [appMsgsArray objectAtIndex:0];
NSString *appDataExpiry = [mainDict valueForKey:@"appdata_expiry"];
[stm deleteOldArticles:[appDataExpiry integerValue]];
NSDate *lastDate = [NSDate date];
[[NSUserDefaults standardUserDefaults] setObject:lastDate forKey:@"LastCheckedDate"];
}
我有一天使用864000.0f值。谁能帮助我,谢谢。
答案 0 :(得分:2)
试试这个:
NSDate *firstDate = [NSDate date];
NSDate *secondDate = [NSDate date];
if ([secondDate timeIntervalSinceDate:firstDate] >= 86400) {
NSLog(@"24 hours have passed...");
}