Skip to content

Instantly share code, notes, and snippets.

@sergiosvieira
Created June 28, 2013 13:10
Show Gist options
  • Save sergiosvieira/5884547 to your computer and use it in GitHub Desktop.
Save sergiosvieira/5884547 to your computer and use it in GitHub Desktop.
Diff between NSDates in seconds
#import <Foundation/Foundation.h>
int main(int argc, char *argv[]) {
@autoreleasepool {
unsigned int unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit | NSDayCalendarUnit | NSMonthCalendarUnit;
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *date1 = [dateFormatter dateFromString:@"2013-06-28 00:00:00"];
NSDate *date2 = [dateFormatter dateFromString:@"2013-06-29 00:00:00"];
NSTimeInterval diff = [date2 timeIntervalSinceDate:date1];
NSLog(@"%f", diff);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment