Created
June 22, 2014 19:10
-
-
Save aliharis/887cc237749c2897ed50 to your computer and use it in GitHub Desktop.
Compare 2 NSDate
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
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