April 12th, 2010, 05:23 PM
TimeIntervalSinceDate Returns Inaccurate Interval
I have the following code... It seems to return an inaccurate calculation. I'm relatively new to Objective C and cannot figure out what is going wrong. By my calculations the difference (in seconds) for 4 days should be somewhere closer to 346,600 than 1917995008. Am I wrong?
This is what gets logged to the console:
NSDictionary *fsAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:uniquePath error:nil];
NSDate *fileDate = [fsAttributes objectForKey:NSFileModificationDate];
NSDateFormatter *format = [[NSDateFormatter alloc] init];
[format setDateFormat:@"MMMM dd, yyyy h:mm a"];
NSString *dateString = [format stringFromDate:fileDate];
NSDate *now = [[NSDate alloc] init];
NSString *nowString = [format stringFromDate:now];
NSLog(@"Now: %@", nowString);
NSLog(@"Cache File Date: %@", dateString);
NSLog(@"Cache File Age in Seconds: %d", [now timeIntervalSinceDate:fileDate]);
2010-04-12 16:15:50.611 Denver United[26329:40b] Now: April 12, 2010 4:15 PM
2010-04-12 16:15:50.612 Denver United[26329:40b] Cache File Date: April 08, 2010 4:23 PM
2010-04-12 16:15:50.614 Denver United[26329:40b] Cache File Age in Seconds: 1917995008
April 12th, 2010, 05:30 PM
Sorry, I just figured it out... I was assuming that I was looking at an integer, but I needed to be looking it as a double.
Hope this helps someone else as retarded as I am.