Created
June 28, 2013 13:10
-
-
Save sergiosvieira/5884547 to your computer and use it in GitHub Desktop.
Diff between NSDates in seconds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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