Skip to content

Instantly share code, notes, and snippets.

@aliharis
Created June 22, 2014 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aliharis/887cc237749c2897ed50 to your computer and use it in GitHub Desktop.
Save aliharis/887cc237749c2897ed50 to your computer and use it in GitHub Desktop.
Compare 2 NSDate
NSDate *dateTraded = [NSDate dateWithTimeIntervalSince1970:1408636621];
NSDateFormatter *_formatter=[[NSDateFormatter alloc]init];
[_formatter setLocale:[NSLocale currentLocale]];
[_formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss ZZZ"];
NSString *_date=[_formatter stringFromDate:dateTraded];
NSLog(@"%@", _date);
NSDate *date1 = _date;
NSDate* current = [NSDate date];
NSDateFormatter *DateFormatter=[[NSDateFormatter alloc] init];
[DateFormatter setLocale:[NSLocale currentLocale]];
[DateFormatter setDateFormat:@"yyyy-MM-dd hh:mm:ss ZZZ"];
NSString *date2=[_formatter stringFromDate:current];
NSLog(@"%@", date2);
if ([date1 compare:date2] == NSOrderedDescending) {
NSLog(@"date1 is later than date2");
} else if ([date1 compare:date2] == NSOrderedAscending) {
NSLog(@"date1 is earlier than date2");
} else {
NSLog(@"dates are the same");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment