i have a problem with the Date Formatter. I Want to compare Two dates, but after i get both of the to the same format, the date is nil.
compareDateNowString = 2014-05-24 19:03:39 +0000
compareDateFininshString = 2014-05-24 18:30:24 +0000
NSDateFormatter *compareFormatter = [[NSDateFormatter alloc]init ];
[compareFormatter setDateFormat:@"dd-MM-yyyy HH.mm"];
NSString *compareDateNowString = [NSString stringWithFormat:@"%@", [NSDate date]];
NSDate *compareDateNow = [compareFormatter dateFromString:compareDateNowString];
NSString *compareDateFinishString = [NSString stringWithFormat:@"%@", [device valueForKey:@"finishDate"]];
NSDate *compareDateFinish = [compareFormatter dateFromString:compareDateFinishString];
NSComparisonResult result = [compareDateNow compare:compareDateFinish];
if(result==NSOrderedAscending)
{
cell.backgroundColor = [UIColor colorWithRed:0.0 green:255.0 blue:0.0 alpha:0.5];
}
else if(result==NSOrderedDescending)
{
cell.backgroundColor = [UIColor colorWithRed:255.0 green:0.0 blue:0.0 alpha:0.5];
}
else
{
NSLog(@"Both dates are the same");
}