-
-
Save adel-ezzat/8fa2e9001df7f4e9810bb54b10ac7bec to your computer and use it in GitHub Desktop.
compare time in objective c
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
+(int)compareOneDay:(NSDate *)oneDay withAnotherDay:(NSDate *)anotherDay | |
{ | |
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; | |
[dateFormatter setDateFormat:@"dd-MM-yyyy"]; | |
NSString *oneDayStr = [dateFormatter stringFromDate:oneDay]; | |
NSString *anotherDayStr = [dateFormatter stringFromDate:anotherDay]; | |
NSDate *dateA = [dateFormatter dateFromString:oneDayStr]; | |
NSDate *dateB = [dateFormatter dateFromString:anotherDayStr]; | |
NSComparisonResult result = [dateA compare:dateB]; | |
NSLog(@"date1 : %@, date2 : %@", oneDay, anotherDay); | |
if (result == NSOrderedDescending) { | |
//NSLog(@"Date1 is in the future"); | |
return 1; | |
} | |
else if (result == NSOrderedAscending){ | |
//NSLog(@"Date1 is in the past"); | |
return -1; | |
} | |
//NSLog(@"Both dates are the same"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment