
April 12th, 2010, 05:23 PM
|
|
Contributing User
|
|
Join Date: Sep 2007
Posts: 33
Time spent in forums: 6 h 52 m 31 sec
Reputation Power: 6
|
|
|
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?
Code:
Code:
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]);
[format release];
This is what gets logged to the console:
Code:
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
|