This question already has answers here:
Number of days between two NSDates [duplicate]
                                
                                    (16个答案)
                                
                        
                                6年前关闭。
            
                    
如何计算目标C格式的两天之间的日期计数差异。

最佳答案

检查安装日期是否已注册,如果已注册,则计算日期,否则进行注册。

if([[NSUserDefaults standardUserDefaults] objectForKey:@"IDate"])
{
    NSDate *iDate = [[NSUserDefaults standardUserDefaults] objectForKey:@"IDate"];
    NSTimeInterval interval = [[NSDate date] timeIntervalSinceDate:iDate];
    int diff=interval/86400;//for converting seconds into days.
    NSLog(@"%d Days",diff);
}
else
{
    [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:@"IDate"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

10-07 23:02