【发布时间】:2023-04-01 00:26:01
【问题描述】:
我的日期格式化程序有问题。我想比较两个日期,但是在我将两个日期都设置为相同格式后,日期为零。
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");
}
【问题讨论】:
标签: ios objective-c nsdateformatter null